更新时间:2023-11-10 15:15:46
也许你可以尝试的 的boost :: MPL ::矢量
。 (我不能完全明白了,你要做的)。
如果你可以使用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.
#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
. (I can't quite see what were you trying to do).
If you could use c++11, making a typelist is much easier with variadic templates (meaning no nasty preprocessor stuff).