对于我使用boost ::元组有点库项目。现在,我面临着通过元编程将我操作的“缺点列表”转回到boost :: tuple < ...>类型的问题。 “脏”的解决方案将提供大量的局部specialications一拉谈到的boost ::元组::利弊<...>回相应的boost ::元组<...>
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> > {}
...
,但这是繁琐且容易出错,尤其是因为我需要与可能的许多元素的元组的支持。这些元组类型是通过操作符重载自动生成的。如果可能的话,我想避免编写这么多的专业化。
如何做到这一点没有任何 C++ 0x特性的任何想法?我想这是不可能的。但也许我忽略了一些东西。
编辑:其实,我与实验的C++ 0x的支持才发现,它并没有正常工作试过这样:
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说:
sorry, unimplemented: cannot expand 'Types ...' into
a fixed-length argument list
:-(
我只是要去直接使用利弊,谢谢! – sellibitze 2010-10-25 13:38:58