类型列表与提升(Type list with boost)

2019-09-16 14:37发布

我继续之前 - 是已经存在或者在升压或一个使用它的小实现的一个类型列表实现? 我还没有发现任何有用的东西为止。

我试图用升压页生成各种大小的列表类:

#define BOOST_PP_LOCAL_MACRO(n) \
    template< BOOST_PP_ENUM_TRAILING_PARAMS(n, class t) >   /*error C2913: explicit specialization; 'typelist1' is not a specialization of a class template*/ \
struct typelist##n \
{ \
    typedef t##n e##n; /*I want n of these*/ \
};

#define Type_At(list, element) list::e##element

#define BOOST_PP_LOCAL_LIMITS (1, 5)

#include BOOST_PP_LOCAL_ITERATE()

请参阅有关问题的代码中的注释。 这是一个体面的方式去制作一个类型串? 这似乎....脏。 我刚听到一个类型串的概念,所以我不熟悉的不同口味。

解:

#define BOOST_MPL_LIMIT_VECTOR_SIZE  50
#include <boost/mpl/vector.hpp>
#include <boost/mpl/at.hpp>

typedef boost::mpl::vector<int, float, double, long, short> vecType;
boost::mpl::at_c<vecType, 3>::type hi = 3;

Answer 1:

也许你可以尝试boost::mpl::vector(我不能完全明白了你想干什么)。

如果你可以用C ++ 11,使得一个类型串是可变参数模板(即没有讨厌的东西预处理器)容易得多。



文章来源: Type list with boost
标签: c++ boost