Boost logo

Boost Users :

Subject: [Boost-users] [bimap] Creating a bimap fom a std::map
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-11-25 10:40:00


I would have thought, naively enough, that one of the common uses of a
bimap was that one should be able to create a bimap from a std::map as
long as the relation between the two types was unique both ways. I was
disconcerted when I did not see a bimap constructor that accepted a
std::map of the same types, but then I saw the constructor which takes
two iterators and decided to try that, like so:

std::map<int,std::string> myMap;
// ... fill myMap
boost::bimap<int,std::string> myBimap(myMap.begin(),myMap.end());

I was met with, in VC9 using Boost 1.40:

"c:\utilities\boost\boost_1_40_0\boost\multi_index_container.hpp(232) :
error C2664: 'std::pair<_Ty1,_Ty2>
boost::multi_index::multi_index_container<Value,IndexSpecifierList,Allocator>::insert_(const
Value &,boost::multi_index::detail::ordered_index_node<Super> *)' :
cannot convert parameter 1 from 'std::pair<_Ty1,_Ty2>' to 'const
boost::bimaps::relation::mutant_relation<TA,TB,Info,force_mutable> &'
1> with
1> [
1>
_Ty1=boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>,std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>>>>>
*,
1> _Ty2=bool,
1>
Value=boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>,
1>
IndexSpecifierList=boost::bimaps::detail::bimap_core<int,TString,boost::mpl::na,boost::mpl::na,boost::mpl::na>::core_indices,
1>
Allocator=std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>>,
1>
Super=boost::multi_index::detail::ordered_index_node<boost::multi_index::detail::index_node_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>,std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>>>>
1> ]
1> and
1> [
1> _Ty1=const int,
1> _Ty2=TString
1> ]
1> and
1> [
1> TA=boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,
1> TB=boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,
1>
Info=boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,
1> force_mutable=true
1> ]
1> Reason: cannot convert from 'std::pair<_Ty1,_Ty2>' to 'const
boost::bimaps::relation::mutant_relation<TA,TB,Info,force_mutable>'
1> with
1> [
1> _Ty1=const int,
1> _Ty2=TString
1> ]
1> and
1> [
1> TA=boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,
1> TB=boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,
1>
Info=boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,
1> force_mutable=true
1> ]
1> No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
1> c:\utilities\boost\boost_1_40_0\boost\bimap\bimap.hpp(247) :
see reference to function template instantiation
'boost::multi_index::multi_index_container<Value,IndexSpecifierList,Allocator>::multi_index_container<InputIterator>(InputIterator,InputIterator,const
boost::tuples::cons<HT,TT> &,const std::allocator<_Ty> &)' being compiled
1> with
1> [
1>
Value=boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>,
1>
IndexSpecifierList=boost::bimaps::detail::bimap_core<int,TString,boost::mpl::na,boost::mpl::na,boost::mpl::na>::core_indices,
1>
Allocator=std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>>,
1>
InputIterator=std::_Tree<std::_Tmap_traits<int,TString,std::less<int>,std::allocator<std::pair<const
int,TString>>,false>>::iterator,
1>
HT=boost::tuples::tuple<boost::multi_index::member<boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,true>,std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,pointer-to-member(0x4)>,std::less<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>>>,
1>
TT=boost::tuples::cons<boost::tuples::tuple<boost::multi_index::member<boost::bimaps::relation::detail::relation_storage<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,true>,int,pointer-to-member(0x0)>,std::less<int>>,boost::multi_index::detail::index_base<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>,boost::bimaps::detail::bimap_core<int,TString,boost::mpl::na,boost::mpl::na,boost::mpl::na>::core_indices,std::allocator<boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>>>::ctor_args_list>,
1>
_Ty=boost::bimaps::relation::mutant_relation<boost::bimaps::tags::tagged<const
int,boost::bimaps::relation::member_at::left>,boost::bimaps::tags::tagged<const
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parameters<boost::mpl::na,boost::mpl::na,boost::mpl::na>::case_NNN::additional_info,true>
1> ]
1>
c:\programming\programs\vc9\xxx\current\yyyyyyyyyy\zzzzzzzzzzzzzzzz.cpp(338)
: see reference to function template instantiation
'boost::bimaps::bimap<KeyTypeA,KeyTypeB>::bimap<std::_Tree<_Traits>::iterator>(InputIterator,InputIterator)'
being compiled
1> with
1> [
1> KeyTypeA=int,
1> KeyTypeB=TString,
1>
_Traits=std::_Tmap_traits<int,TString,std::less<int>,std::allocator<std::pair<const
int,TString>>,false>,
1>
InputIterator=std::_Tree<std::_Tmap_traits<int,TString,std::less<int>,std::allocator<std::pair<const
int,TString>>,false>>::iterator
1> ]"

So evidently that does not work.

What is the problem with creating a bimap from the data in a std::map ?
It seems as if it should be a no-braine and one of the chief selling
points of using a bimap.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net