1
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

Neel Basu
  • 12,638
  • 12
  • 82
  • 146

1 Answers1

0

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.

  • Hmm then what is the generic way of insertion ? if its `set_of` I'll have to use `insert` but if its `vector_of` I need to `push_back` or pass end(). and to make this generic I'll need compile type checks like `enable_if` that will be too complex – Neel Basu May 04 '13 at 16:35
  • `insert(Iterator, ValueType)` works with all the views that can insert. But if you use `map.end()` with a `set_of` view you will get worse performance that if you had used an iterator that preceded the point of insertion (O(log(N)) vs O(1)). I believe this is the reason why it is not as generic as you want, you are supposed to choose a bimap combination that suits your performance requirements and then use the methods allowed in that combination. – user2349552 May 04 '13 at 17:24
  • I have changed the comment in the beginning of the question, it know reflects my level of knowledge of the library more accurately. You should probably wait for a more reliable answer. – user2349552 May 04 '13 at 17:30