C ++ code here:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp
really is a labeled union, as it may contain duplicate types. One nice feature is that tags can be enumerations; therefore, tags can have meaningful names.
Unfortunately, compilation time is pretty bad, I think, because the implementation uses recursive inheritance. OTOH, perhaps compilers will eventually figure out a way to reduce compilation time.
OTOH, if you want to stick with boost :: variant, you can wrap types as suggested by Mark B. However, instead of the descriptive names of the Mark B classes that require some thought, you can use fusion::pair<mpl::int_<tag>,T_tag> where T_tag is the tag element in the fusion::vector source. IOW:
variant < fusion::pair<mpl::int_<1>,T1> , fusion::pair<mpl::int_<2>,T2> ... , fusion::pair<mpl::int_<n>,Tn> >
How to merge documents:
http://www.boost.org/doc/libs/1_55_0/libs/fusion/doc/html/fusion/support/pair.html
say, fusion::pair allocates only space for the argument of the 2nd template; therefore, this should not take up more space than boost::variant<T1,T2,...,Tn> .
NTN.
-regards, Larry
source share