C 提升:简单的嵌套字典
C++ Boost: Simple nested dictionary?
用字符串键和字符串/int/dictionary值实现嵌套词典的最简单方法是什么?
我到目前为止尝试的是一个奇怪的:
boost::fusion::map<std::string, boost:variant<std::string, int, boost::fusion::map<std::string, boost:variant<std::string, int>>>>
这看起来像是深度2,而且看起来绝对无法正常工作。即使愿意,我也对如何使用它感到困惑。
有什么想法?
您可以这样定义它,
template<int N> struct my_map {
typedef boost::variant<int, std::string, typename my_map<N-1>::type> value_type;
typedef std::map<std::string, value_type> type;
};
template<> struct my_map<1> {
typedef boost::variant<int, std::string> value_type;
typedef std::map<std::string, value_type> type;
};
可能用boost::fusion::map
替换std::map
,但是也许您会以更简单的设计使用(智能)指针将其链接到nullptr
时,当您需要终止时。
相关文章:
- 嵌套在类中时无法设置成员数据
- 无法访问嵌套类.类的使用无效
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 如何在C++中初始化嵌套类中的2个memeber
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 在C++中搜索嵌套多映射值
- 在C++中将矢量转换为嵌套地图
- C++嵌套if语句,基本货币交换
- 在nlohmann json中,如何将嵌套对象的数组转换为嵌套结构的向量
- 嵌套的匿名命名空间
- 了解嵌套循环打印星号图案
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 嵌套for循环C++的问题(初学者)
- 从嵌套在std::映射中的std::列表中删除元素的最佳方式
- 用C#中的并集模拟C++嵌套结构
- 部分专业化和嵌套模板
- 嵌套While循环不起作用(C++问题)
- C++-模板嵌套类的引用初始化无效
- 在 c++ 中访问嵌套字典unordered_map<字符串、void*>?
- C 提升:简单的嵌套字典