typedef boost::bimap<boost::bimaps::vector_of<int>, boost::bimaps::vector_of<float> > bimap_t;
bimap_t mp;
mp.left.insert(bimap_t::left_value_type(2, 2.0f));

Why doesn't this work ? and gives compiler error on insert() It cannot find any insert() that takes bimap_t::left_value_type as argument.

However boost::bimap<boost::bimaps::set_of<int>, boost::bimaps::vector_of<float> > works. looks like the left cannot be vector. but as its bi directional it shouldn't matter

没有正确的解决方案

其他提示

I have never used Boost.Bimap before, but looking through the documentation it seems like the types of the left and right views, and accordingly the member functions you can use, depend on the collections you use as template parameters. You can see here the methods you can use with a vector_of view. You could use:

mp.left.insert(mp.left.end(), bimap_t::left_value_type(2,2.0f));
mp.left.push_back(bimap_t::left_value_type(2,2.0f));

You could also use:

mp.left.push_front(bimap_t::left_value_type(2,2.0f));

but it is not recommended for performance reasons.

PS: If you use bimap<boost::bimaps::set_of<int>, boost::bimaps::vector_of<float> > your insert will work with the left view but it will fail with the right one.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top