3

在我继续之前 - 在 boost 或使用它的小型实现中是否已经有类型列表实现?到目前为止,我还没有发现任何有用的东西。

我正在尝试使用 boost pp 生成各种大小的列表类:

#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()

请参阅问题代码中的注释。这是制作类型列表的好方法吗?好像……脏。我只是听说过 typelist 的概念,所以我不熟悉不同的风格。

解决方案:

#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;
4

1 回答 1

3

也许你可以试试boost::mpl::vector(我不太明白你想做什么)。

如果您可以使用 c++11,则使用可变参数模板制作类型列表要容易得多(这意味着没有讨厌的预处理器的东西)。

于 2012-04-18T11:21:38.673 回答