提升:使用运算符 [] 访问 bimap
Boost: Accessing bimap using operator[]
在下面的代码中:
typedef bimap< set_of< std::string >, list_of< int > > bm_type;
bm_type bm;
bm.left["one"] = 1; // "one" -> 1
bm.left["one"] = 2; // replaced: "one" -> 2
bm.right[2] = "two"; // Compile error
如何摆脱编译错误?难道不能用operator[]
访问正确的视图吗?
list_of
没有operator[]
。
看看 http://www.boost.org/doc/libs/1_47_0/libs/bimap/doc/html/boost_bimap/reference/list_of_reference.html
这段代码没有任何意义。列表没有operator[]
因为您必须选择在创建元素时插入元素的位置。由于列表不是内部排序的(如地图),因此2
可以位于列表的开头、列表的末尾、列表的中间或其他任何位置。
(Boost的list_of
模仿标准list
的语义。
相关文章:
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 用于访问容器<T>数据成员的正确 API
- 访问者访问变体并返回不同类型时出错
- 尝试通过多个向量访问变量时,向量下标超出范围
- 无法访问嵌套类.类的使用无效
- 写入位置0x0000000C时发生访问冲突
- 我们可以访问一个不存在的联盟的成员吗
- C++从另一个类访问公共静态向量的正确方法是什么
- 我的简单if-else语句是如何无法访问的代码
- 从C++dll访问C#中的一行主要参数
- 如何在c++中只将键插入到bimap的一侧
- 概念TS检查忽略私有访问修饰符
- 访问被拒绝后,c++中的故障保护代码
- 在c++中访问int到类对象的映射时出错
- 我想访问std::unique_ptr中的一个特定元素
- 为什么示例代码访问IUnknown中已删除的内存
- 访问bimap中具有键的值
- 提升:使用运算符 [] 访问 bimap