Boost logo

Boost Users :

Subject: Re: [Boost-users] [bimap] Creating a bimap fom a std::map
From: Matias Capeletto (matias.capeletto_at_[hidden])
Date: 2009-11-25 17:16:34


On Wed, Nov 25, 2009 at 6:08 PM, Edward Diener <eldiener_at_[hidden]> wrote:
> Matias Capeletto wrote:
>> ... you have just wrote down here
>> why it is not a good idea to provide this constructor. Not only it
>> breaks the symmetry, the real problem is that following your idea of
>> automatic conversion between pairs and relations we bump into
>> ambiguities. Imagine you now have a bimap<A,A>, and you use your
>> constructor with a map<A,A>... it is not clear which side is the left
>> and which side is the right.
>
> Are you saying that if I insert map items on the left side of a bimap I can
> not access them from the right side of the bimap, or vice versa ? That would
> seem to make the bimap fairly useless. If not, in your example of bimap<A,A>
> and map<A,A> it should make no difference whatever into which side the map
> pairs are originally inserted.

I am not saying that.
The problem is that If you have a std::map<int,int> m;
with the elements (1,10), (2,20), (3,30), (4,40), and you code:

  boost::bimap<int,int> bm( m );

It is ambiguous, you just have to choose to view the map as the left
view of the bimap or as the right one, and the only way to get out of
this problem is to give one of the views priority over the other one
which goes against the design of the library... or to ask the users to
explicitly show their intention:

  boost::bimap<int,int> bm();
  bm.left.insert( m.begin(), m.end() );

Regards
Matias


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