Boost.Fusion から Boost.Variant を定義
ふと、思いついたので書いてみた。
[ソース]
#include <boost/variant.hpp> #include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/mpl.hpp> #include <boost/fusion/include/for_each.hpp> #include <boost/mpl/unique.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/type_traits/is_same.hpp> #include <iostream> #include <string> int main(){ namespace fusion = boost::fusion; namespace mpl = boost::mpl; using mpl::_1; using mpl::_2; typedef fusion::vector<int, std::string, float, std::string> seq_type; typedef boost::make_variant_over< mpl::unique<seq_type, boost::is_same<_1, _2> >::type >::type var_type; auto v = seq_type(42, "homu", 3.14f, "mado"); fusion::for_each(v, [](var_type const& var){ std::cout << var << std::endl; }); return 0; }
[出力]
42 homu 3.14 mado
こういう使い方もありかしら?
[boost]
- ver 1.48.0