C++ 相互递归的变体类型
C++ Mutually Recursive Variant Type
我正在尝试使用变体在c ++中表示PDF对象类型。PDF 对象是以下对象之一:
-
Boolean
-
Integer
-
Real
-
String
-
Name
-
Stream
-
Array<Object>
-
Map<Object, Object>
如您所见,Object
类型是相互递归的,因为Array
类型需要Map
类型的声明,而类型的声明需要Array
类型的声明。我怎样才能在 c++ 中表示这种类型?如果变体不是最好的方法,那是什么?
这是我到目前为止尝试过的方法,但由于std::unordered_map
(我认为(的要求,它无法编译 http://coliru.stacked-crooked.com/a/699082582e73376e
既然你使用的是boost::variant
,那么使用它的递归包装器有什么问题?
- recursive_variant
- recursive_wrapper
您可以在教程中看到一个简短的示例:
typedef boost::make_recursive_variant<
int
, std::vector< boost::recursive_variant_ >
>::type int_tree_t;
std::vector< int_tree_t > subresult;
subresult.push_back(3);
subresult.push_back(5);
std::vector< int_tree_t > result;
result.push_back(1);
result.push_back(subresult);
result.push_back(7);
int_tree_t var(result);
它按预期工作。
相关文章:
- 递归模板化函数不能分配给具有常量限定类型"const tt &"的变量"state"
- 从类型列表中递归删除重复项会导致编译器堆空间错误 (VS2017)
- 此递归模板类型定义是否有效C++?
- 递归函数的返回类型推导
- 在迭代模板类型列表时无法停止递归
- 如何使用common_type和模板递归类型重载运算符+
- C++ 相互递归的变体类型(再次)
- C++ 引用类型作为递归函数参数
- 我的编辑距离递归代码中的字符类型有问题
- 区分递归类型的结合
- 具有类型名的模板的递归实例化
- C++ 递归函数类型
- 是否有一个术语来表示"single mutex deadlock"(具有非递归互斥锁的死锁类型情况)?
- C 递归类型定义
- 我如何实现递归函数的模板,该模板允许C 中的许多不确定数据类型的参数
- 用类型的递归继承获得Variadic模板的阴影成员
- 前向声明不完整类型,递归
- C++:类型别名中的递归依赖关系
- 递归中不同参数类型的变元模板函数
- C 模板递归以检查std :: tuple中的类型