Hi, 

I am facing compilation error in the following code. I do understand why the error is, but I could not find a good solution. Here is my code and question explained in detail

What I want to do:   I want to store a key- value pair where both key and its respective values is unique. But After I create a map, I want to use the VALUE and get the corresponding key. Essentially the best way is a bimap. So I do the following using associative property maps. 

What I did:
1. define a bimap  (my_bimap )
2. define associative property map for left view of bimap    ( right_asso_bimap )
3. define associative property map for right view of bimap  ( left_asso_bimap )
4. fill the bimap using left view associative property map. 
   i.e.  use boost::put( left_asso_bimap, key, value )
5. Now using right view associative property map, retrieve key for given value
   i.e. use  boost::get( right_asso_bimap, value )

My main motive is to use GET and PUT helper functions for insertion and retrieval from a bimap.  Use PUT to insert in LEFT BIMAP. and Use GET to retrieve from RIGHT BIMAP. 

I know the error is because of non-const-ness of the iterators because of which I cannot de-reference using iterators. But what would be the alternative to this ? 
This link here explains how to define parameters for bimap in order for iterators to be mutable. 

http://www.boost.org/doc/libs/1_55_0/libs/bimap/doc/html/boost_bimap/the_tutorial/differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.iterator__value_type 

But I get the error below: 
In file included from main.cpp:2:0:
/usr/local/include/boost/property_map/property_map.hpp: In instantiation of 'boost::associative_property_map<UniquePairAssociativeContainer>::value_type& boost::associative_property_map<UniquePairAssociativeContainer>::operator[](const key_type&) const [with UniquePairAssociativeContainer = boost::bimaps::views::list_map_view<boost::bimaps::relation::member_at::right, boost::bimaps::detail::bimap_core<int, boost::bimaps::list_of<long unsigned int>, mpl_::na, mpl_::na, mpl_::na> > boost::associative_property_map<UniquePairAssociativeContainer>::reference = const int&; boost::associative_property_map<UniquePairAssociativeContainer>::value_type = const int; boost::associative_property_map<UniquePairAssociativeContainer>::key_type = long unsigned int]':
/usr/local/include/boost/property_map/property_map.hpp:357:54:   required from 'Reference boost::get(const boost::put_get_helper<Reference, PropertyMap>&, const K&) [with PropertyMap = boost::associative_property_map<boost::bimaps::views::list_map_view<boost::bimaps::relation::member_at::right, boost::bimaps::detail::bimap_core<int, boost::bimaps::list_of<long unsigned int>, mpl_::na, mpl_::na, mpl_::na> > > Reference = const int&; K = int]'
main.cpp:41:35:   required from here
/usr/local/include/boost/property_map/property_map.hpp:502:20: error: no match for 'operator[]' (operand types are 'boost::associative_property_map<boost::bimaps::views::list_map_view<boost::bimaps::relation::member_at::right, boost::bimaps::detail::bimap_core<int, boost::bimaps::list_of<long unsigned int>, mpl_::na, mpl_::na, mpl_::na> > >::C {aka boost::bimaps::views::list_map_view<boost::bimaps::relation::member_at::right, boost::bimaps::detail::bimap_core<int, boost::bimaps::list_of<long unsigned int>, mpl_::na, mpl_::na, mpl_::na> >}' and 'const key_type {aka const long unsigned int}')
       return (*m_c)[k];
                    ^



Here my code. You can also see the code here  on this website link: http://coliru.stacked-crooked.com/a/59cbf2c564bf22b2

#include <boost/bimap.hpp> 
#include <boost/property_map/property_map.hpp> 
#include <boost/bimap/property_map/set_support.hpp>
#include <boost/bimap/list_of.hpp>
#include <iostream> 

using namespace boost; 

int main() {
typedef int vertex_descriptor_t;
namespace bm = boost::bimaps;
typedef bm::bimap< vertex_descriptor_t, bm::list_of<size_t> > vd_idx_bimap_t;
typedef boost::associative_property_map<vd_idx_bimap_t::left_map>    Lasso_vd_idx_bimap_t;
typedef boost::associative_property_map<vd_idx_bimap_t::right_map>   Rasso_vd_idx_bimap_t;

// define bimap and assoc prop map for it
vd_idx_bimap_t        my_bimap;
Lasso_vd_idx_bimap_t  Lmy_asso_bimap(my_bimap.left );
Rasso_vd_idx_bimap_t  Rmy_asso_bimap(my_bimap.right);

typedef typename vd_idx_bimap_t::value_type value_type;    
my_bimap.insert( value_type( 1, 100 ) );
my_bimap.insert( value_type( 2, 200 ) );

int z = 1;
std::cout << "value = " << get ( my_bimap.left, z ) << std::endl;    // prints correctly value = 100

// use left asso bimap for inserting to bimap 
boost::put( Lmy_asso_bimap, 3, 300 );   // correct

// print bimap using left view
for(auto t = my_bimap.left.begin(); t != my_bimap.left.end(); ++t)
    std::cout << t->first << " " << t->second <<  "\n";

int y = 2;
z = boost::get( Lmy_asso_bimap, y  );   // CORRECT OUTPUT for left view 
std::cout << "value = " << z << std::endl;

// Use right asso bimap to get key based on supplied value
y = 100;
z = boost::get( Rmy_asso_bimap, y );    // -->> ERROR HERE for right view
std::cout << "value = " << z << std::endl;

// print map again. (right view)
for(auto t = my_bimap.right.begin(); t != my_bimap.right.end(); ++t)
    std::cout << t->first << " " << t->second <<  "\n";

} 



Please let me know whether this is a potential bug, or the code semantics is incorrect. Or the current library cannot support this. ?



Regards,
Aniket Pugaonkar




--

Thanks and regards,
Aniket Pugaonkar