No std::tuple<A, B>
means A AND B.
If you want a typesafe union-like container, have a look to boost variant.
boost::variant<int, std::string> v;
v = "hello";
std::cout << v << std::endl;
It does provide safe traversing with visitors:
class times_two_visitor
: public boost::static_visitor<>
{
public:
void operator()(int & i) const
{
i *= 2;
}
void operator()(std::string & str) const
{
str += str;
}
};
Or even direct accessors that can throw if the type is not good:
std::string& str = boost::get<std::string>(v);
(Code taken from boost variant basic tutorial)