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 myMap;
// ... fill myMap
boost::bimap 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::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 &'
1> with
1> [
1>
_Ty1=boost::multi_index::detail::ordered_index_node,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::mpl::na,boost::mpl::na,boost::mpl::na::case_NNN::additional_info,true>,std::allocator,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::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,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::mpl::na,boost::mpl::na,boost::mpl::na::case_NNN::additional_info,true>,
1>
IndexSpecifierList=boost::bimaps::detail::bimap_core::core_indices,
1>
Allocator=std::allocator,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::mpl::na,boost::mpl::na,boost::mpl::na::case_NNN::additional_info,true>>,
1>
Super=boost::multi_index::detail::ordered_index_node,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::mpl::na,boost::mpl::na,boost::mpl::na::case_NNN::additional_info,true>,std::allocator,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::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,
1> TB=boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,
1>
Info=boost::bimaps::detail::manage_additional_parametersboost::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'
1> with
1> [
1> _Ty1=const int,
1> _Ty2=TString
1> ]
1> and
1> [
1> TA=boost::bimaps::tags::tagged,
1> TB=boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,
1>
Info=boost::bimaps::detail::manage_additional_parametersboost::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::multi_index_container<InputIterator>(InputIterator,InputIterator,const
boost::tuples::cons &,const std::allocator<_Ty> &)' being compiled
1> with
1> [
1>
Value=boost::bimaps::relation::mutant_relation,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::mpl::na,boost::mpl::na,boost::mpl::na::case_NNN::additional_info,true>,
1>
IndexSpecifierList=boost::bimaps::detail::bimap_core::core_indices,
1>
Allocator=std::allocator,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::mpl::na,boost::mpl::na,boost::mpl::na::case_NNN::additional_info,true>>,
1>
InputIterator=std::_Tree>,false>>::iterator,
1>
HT=boost::tuples::tuple,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,true>,std::basic_string,std::allocator>,pointer-to-member(0x4)>,std::less,std::allocator>>>,
1>
TT=boost::tuples::cons,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,true>,int,pointer-to-member(0x0)>,std::less<int>>,boost::multi_index::detail::index_base,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::mpl::na,boost::mpl::na,boost::mpl::na::case_NNN::additional_info,true>,boost::bimaps::detail::bimap_core::core_indices,std::allocator,boost::bimaps::tags::tagged,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::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,std::allocator>,boost::bimaps::relation::member_at::right>,boost::bimaps::detail::manage_additional_parametersboost::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::bimap::iterator>(InputIterator,InputIterator)'
being compiled
1> with
1> [
1> KeyTypeA=int,
1> KeyTypeB=TString,
1>
_Traits=std::_Tmap_traits>,false>,
1>
InputIterator=std::_Tree>,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.