使用mpl::vector定义boost::变体类型
Using mpl::vector to define boost::variant types
我使用库boost::variant
来存储大量类型。随着类型的增加,我很快就会达到20种的极限。在文档中,似乎可以使用mpl::vector
定义变体,它允许超过20种类型(如果我是正确的,最多50种)。我尝试这样替换我的变量定义:
#include <boost/variant.hpp>
#include <boost/mpl/vector.hpp>
typedef boost::mpl::vector<
float,
math::float2,
math::float3,
relative_point<1>,
relative_point<2>,
relative_point<3>,
std::string,
color,
group,
dictionnary,
reference,
line,
strip,
text,
font
> variant_mpl_vec;
typedef boost::make_variant_over<variant_mpl_vec>::type data_type;
// This is the old definition
/*typedef boost::variant<
float,
math::float2,
math::float3,
relative_point<1>,
relative_point<2>,
relative_point<3>,
std::string,
color,
group,
dictionnary,
reference,
line,
strip,
text,
font
> data_type;*/
我直接写代码。大多数类型都是包含很少数据的结构体。
编译时,我得到了一个奇怪的:
error: no matching function for call to ‘boost::detail::variant::make_initializer_node::apply<boost::mpl::pair< ... and lots more ...
以前的变量定义工作得很好,所以我很惊讶我的替换不起作用。我是新的mpl
所以也许我错过了一些东西-但找不到什么!我做得好吗?
变量类型定义是正确的,问题是由于程序中的泛型函数将任意变量作为参数。事实上,make_variant_over<mpl::vector<T0, T1, ...>>
的行为类似于variant<T0, T1, ...>
,但不是相同的类型:它是variant<over_sequence<vector<T0, T1, ...>>>
(因此T0对应于over_sequence<vector<T0, T1, ...>>
)。
相关文章:
- boost 是否有按特殊类型值编码状态"compact optional"?
- 像union_这样的 Boost.Geometry 操作如何处理浮点类型的基本不精确性?
- 来自 Android 应用程序内部的 boost 类型的 boost::wrapexcept<boost::system::system_error> 的未捕获异常
- 使用 Boost.Spirit 解析具有混合数据类型的 OBJ 文件?
- 使用自定义访问者时具有自定义类型的提升变体失败(源自 boost::static_visitor)
- 在其他容器中使用 boost::container::static_vector 时,GCC 编译错误"将'const s'绑定到类型's&'的引用丢弃限定符"
- Boost.Python :C++模板类型匹配的嵌套命名空间
- 我正在将一个 std::string 传递给一个 boost 函数,该函数对该类型进行常量引用,但该值发生了变化
- Boost.Hana:在 constexpr 上下文中将值元组转换为相应类型的元组
- 如何在Boost::program_options配置文件中为非字符串的自定义选项值类型处理空格
- 从具有部分专用化的boost:hana::set中提取类型失败
- boost odeint 中的受控误差步进器是否支持复杂的数据类型?
- boost::p rogram_options 验证每个参数而不是每个参数类型?
- boost multi_index - 如果元素类型仅支持移动语义,如何遍历它?
- 标准::键映射和/或 boost::any 类型的值的类型检查
- 是否可以使用 Boost.Hana 将 std::array 解压缩到非类型模板参数包中
- 检查两个 Boost.MPL 序列是否按任何顺序包含相同的类型
- 任何表示具有有序元素的对的 stl/boost 类型
- 抽象与线程相关的 STL 和 Boost 类型和方法
- Boost类型擦除的实践和发现