gpt4 book ai didi

c++ - 带 boost 的类型列表

转载 作者:太空狗 更新时间:2023-10-29 21:26:59 25 4
gpt4 key购买 nike

在我继续之前 - 在 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()

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

解决方案:

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

最佳答案

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

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

关于c++ - 带 boost 的类型列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10208180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com