I am trying to use the bracket operator on a boost::bimap
but without success.
For the problem I seek to solve I need a bimap
that fulfills the following requirement:
- left sorted, unique
int
- right non unique, non sorted type
This lead me to choose the following typedef
for my bimap
,
typedef bimap<int, multiset_of<int> > bm;
I want to use the bracket operator on this type but without success. This is the code that I use,
#include <iostream>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
using namespace std;
using namespace boost::bimaps;
int main()
{
typedef bimap<int, multiset_of<int> > bm;
bm mapping;
mapping.insert(bm::value_type(1, 1));
mapping.insert(bm::value_type(2, 1));
mapping.insert(bm::value_type(3, 4));
for (auto it : {1 , 2, 3})
mapping.left[it] = it;
for (auto it : mapping.left)
cout << "{ " << it.first << ", " << it.second << " } ";
return 0;
}
This gives me a long compile error where the essential bit seems to be
/usr/include/boost/bimap/detail/map_view_base.hpp:351:9: error: no matching function for call to 'assertion_failed'
BOOST_BIMAP_STATIC_ERROR( OPERATOR_BRACKET_IS_NOT_SUPPORTED, (Derived));
(full live live example and compiler output can be found on: rextester)
I tried the solution below but it still yields errors,
#include <iostream>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
using namespace std;
using namespace boost::bimaps;
int main()
{
typedef bimap<int, multiset_of<int> > bm;
typedef bm::left_map map_type;
bm mapping;
map_type& m = mapping.left;
mapping.insert(bm::value_type(1, 1));
mapping.insert(bm::value_type(2, 1));
mapping.insert(bm::value_type(3, 4));
for (auto it : {1 , 2, 3})
m[it] = it;
for (auto it : mapping.left)
cout << "{ " << it.first << ", " << it.second << " } ";
return 0;
}
How can I declare a bimap
that fulfills my requirements and supports the bracket operator?