2

在以下代码中:

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[]

4

2 回答 2

2

list_of没有operator[]

看看http://www.boost.org/doc/libs/1_47_0/libs/bimap/doc/html/boost_bimap/reference/list_of_reference.html

于 2012-12-10T10:49:24.593 回答
1

这段代码没有任何意义。列表没有,operator[]因为如果创建元素,您必须选择插入元素的位置。由于列表不是内部排序的(就像地图一样),所以 a2可以位于列表的开头、列表的结尾、列表的中间或其他任何地方。

(Boostlist_of模仿标准的语义list。)

于 2012-12-10T10:49:21.910 回答