Boost.Variant で Sequence を扱う

#include <boost/variant.hpp>

#include <boost/mpl/equal.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/back.hpp>
#include <boost/mpl/copy.hpp>
#include <string>

namespace mpl = boost::mpl;

typedef mpl::vector<int, float, std::string> seq;

// boost::make_variant_over を使用して、MPL の Sequence から variant を定義出来る
typedef boost::make_variant_over<seq>::type var_type;

// boost::variant::types で、Sequence を取得出来る
BOOST_MPL_ASSERT(( mpl::equal<
    var_type::types,
    boost::variant<int, float, std::string>::types
>));

BOOST_MPL_ASSERT(( mpl::equal_to<
    mpl::size<boost::variant<int, float, double, char>::types>,
    mpl::int_<4>
> ));

// 型を追加する
typedef mpl::copy<
    var_type::types,
    mpl::back_inserter<mpl::vector<char> >
>::type seq2;
typedef boost::make_variant_over<seq2>::type var_type2;

BOOST_MPL_ASSERT(( mpl::equal<
    var_type2::types,
    boost::variant<char, int, float, std::string>::types
>));

int main(){
    var_type2 v1(1);
    var_type2 v2('c');
    var_type2 v3(0.0f);
    var_type2 v4(std::string(""));
}


[boost]
ver 1.46.1
[参照]
http://www.boost.org/doc/libs/1_37_0/doc/html/boost/make_variant_over.html
http://www.boost.org/doc/libs/1_46_1/doc/html/boost/variant.html