[tuple] generating tuples from type lists

Hi, Is it possible to do this trick during compilation time? I was able to go from type lists to boost::cons but I can't find a way to make that last step. Thx. ImRe

Roman Perepelitsa wrote:
<imre <at> u-tx.com> writes:
Is it possible to do this trick during compilation time? I was able to go from type lists to boost::cons but I can't find a way to make that last step.
Hi,
Maybe boost::fusion can help.
Sure: typename boost::fusion::result_of::as_vector<your_type_list>::type Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

<imre@u-tx.com> writes:
Hi,
Is it possible to do this trick during compilation time? I was able to go from type lists to boost::cons but I can't find a way to make that last step.
Not sure what you mean by "that last step..." namespace mpl = boost::mpl; using namespace mpl::placeholders; typedef mpl::vector<int, long, char const*> types; typedef mpl::fold<types, boost::cons<_2,_1> >::type tuple_type; tuple_type some_tuple; If you want it to be a specialization of the boost::tuple template (misguided, IMO) you can do it, but not "algorithmically." You need a bunch of partial specializations: template <class V, std::size_t n = mpl::size<V>::type::value > struct types_to_tuple; template <class V> struct types_to_tuple<V, 0> { typedef boost::tuple<> type; } template <class V> struct types_to_tuple<V, 1> { typedef boost::tuple<typename mpl::at_n<0>::type> type; } template <class V> struct types_to_tuple<V, 2> { typedef boost::tuple<typename mpl::at_n<0>::type, typename mpl::at_n<1>::type> type; } etc. This works on mpl::vector. Getting it to work on mpl::list is slightly more complicated. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (4)
-
David Abrahams
-
imre@u-tx.com
-
Joel de Guzman
-
Roman Perepelitsa