Boost logo

Boost Users :

Subject: Re: [Boost-users] [bimap] Creating a bimap fom a std::map
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-11-25 17:35:57


Matias Capeletto wrote:
> 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() );

But if I do the above I can still access the bimap from either the left
or right views. So it little matters which one I use to actually insert
my map entries. Whether I go:

bm.left.insert( m.begin(), m.end() );

or

bm.right.insert( m.begin(), m.end() );

,when both types are the same, is totally irrelevant to further use of
the bimap. Is this not correct ?

So therefore if you create a bimap constructor which takes a map, and
both types are exactly the same, it is irrelevant if internally you use

bm.left.insert( m.begin(), m.end() );

or

bm.right.insert( m.begin(), m.end() );

to populate the bimap. Therefore your argument that having to decide how
to populate the bimap from a map, when both types are the same, is a
reason not to create a constructor which takes a map is not valid to me.


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