问题描述
在我继续前进 - 在那里已经不是在升压型列表实现或者使用它的小的实现?我还没有发现任何迄今为止有用的。
我试图用升压页生成不同大小的列表类:
的#define BOOST_PP_LOCAL_MACRO(N)\\
模板< BOOST_PP_ENUM_TRAILING_PARAMS(N,T级)GT; / *错误C2913:明确的专业化; typelist1'不是一个类模板的特* / \\
结构类型串##ñ\\
{\\
typedef的ŧ##否E ## N; / *我想这些N * / \\
};#定义Type_At(列表元素)列表::电子商务##元的#define BOOST_PP_LOCAL_LIMITS(1,5)的#include BOOST_PP_LOCAL_ITERATE()
见的问题code的意见。这是一个体面的方式去制作一个类型?这似乎....脏。我刚听到一个类型的概念,所以我不熟悉的不同口味。
解决方案:
的#define BOOST_MPL_LIMIT_VECTOR_SIZE 50
#包括LT&;提升/ MPL / vector.hpp>
#包括LT&;提升/ MPL / at.hpp>TYPEDEF提振:: MPL ::矢量<整型,浮点,双,长,短> vecType;
提高:: MPL :: at_c< vecType,3 GT; ::类型喜= 3;
也许你可以尝试的。 (我不能完全明白了,你要做的)。
如果你可以使用C ++ 11,使得一个类型是可变参数模板(即没有讨厌的preprocessor东西)容易得多。
Before I move on - is there already a type list implementation either in boost or a small implementation that uses it? I haven't found anything useful so far.
I'm attempting to use boost pp to generate list classes of various sizes:
#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()
See the comments in the code of the issues. Is this a decent way to go about making a typelist? It seems.... dirty. I only just heard about the concept of a typelist, so I'm not familiar with different flavors.
Solution:
#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;
Maybe you could try boost::mpl::vector
.
If you could use c++11, making a typelist is much easier with variadic templates (meaning no nasty preprocessor stuff).
这篇关于类型列表与提升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!