For a little library project I'm using boost::tuple. Right now, I'm facing the problem of turning a "cons list" I operated on via metaprogramming back to a boost::tuple<...> type. The "dirty" solution would be to provide lots of partial specialications a la
template<class T> struct id{typedef T type;};
template<class TL> struct type_list_to_tuple_type;
template<class T1>
struct type_list_to_tuple_type<
boost::tuples::cons<T1,boost::tuples::null_type>
> : id<boost::tuple<T1> > {}
template<class T1, class T2>
struct type_list_to_tuple_type<
boost::tuples::cons<T1,
boost::tuples::cons<T2,boost::tuples::null_type> >
> : id<boost::tuple<T1,T2> > {}
template<class T1, class T2, class T3>
struct type_list_to_tuple_type<
boost::tuples::cons<T1,
boost::tuples::cons<T2,
boost::tuples::cons<T3,boost::tuples::null_type> > >
> : id<boost::tuple<T1,T2,T3> > {}
...
But this is tedious and error-prone, especially because I need support for tuples with possibly many elements. These tuple types are automatically generated via operator overloading. If possible, I'd like to avoid having to write so many specializations.
Any idea on how to do that without any C++0x features? I suppose it's not possible. But maybe I'm overlooking something.
Edit: I actually tried this with the experimental C++0x support only to find out that it doesn't yet work:
template<class TPH>
class type_pack_holder_to_tuple_type;
template<class...Types>
class type_pack_holder_to_tuple_type<
type_pack_holder<Types...> >
: id< boost::tuple<Types...> > {};
G++ 4.5.1 says:
sorry, unimplemented: cannot expand 'Types ...' into
a fixed-length argument list
:-(