No std::tuple<A, B> means A AND B. If you want to create a typical merged container, look at the boost option .
boost::variant<int, std::string> v; v = "hello"; std::cout << v << std::endl;
It provides safe movement of 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 suitable:
std::string& str = boost::get<std::string>(v);
(Code taken from basic acceleration tutorial )
source share