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-27 14:59:13


Lex Wassenberg wrote:
> I am not sure wether I understand this whole discussion, but I think
> that I do so I would like Edward to consider this:
>
> Suppose you have a std::map<int, int> m with the elements (1,10),
> (2,20), (3,20), (4,20), (5,30), and you code:
> Boost::bimap<int,int> bm(m);
>
> Now what??

Bimap automatically adds the map data to the left side of the bimap. If
any data can not be added, such as the (3,20), (4,20), it acts in
exactly the same fashion as it normally would when one tries to insert a
data pair which is not distinct both ways.

My point is that I wanted a constructor as above:

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

to do essentially:

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

Evidently the implementor of bimap does not agree so I have chosen not
to pursue this suggestion any further. But I doubt I will be the last
person suggesting this.

>
> Regards
>
> Lex
>
>
>> -----Oorspronkelijk bericht-----
>> Van: boost-users-bounces_at_[hidden] [mailto:boost-users-
>> bounces_at_[hidden]] Namens Matias Capeletto
>> Verzonden: Wednesday, 25 November 2009 23:50
>> Aan: boost-users_at_[hidden]
>> Onderwerp: Re: [Boost-users] [bimap] Creating a bimap fom a std::map
>>
>> On Wed, Nov 25, 2009 at 5:35 PM, Edward Diener
> <eldiener_at_[hidden]>
>> wrote:
>>> 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 ?
>> No, it is not correct. A bimap is a mapping between two sets of
>> elements (named the left set, and the right set) that can be viewed as
>> a std map<L,R> or as a std map<R, L>. In this particular example both
>> sets hold elements of the same type but which one is the left and
>> which one is the right matters. Imagine that you need a mapping
>> between names and surnames
>> (bimap<tagged<string,name>,tagged<string,surname> >), and you want to
>> insert from a std::map<string,string> that maps from surnames to
>> names.
>> I hope it is more clear now.
>> Regards
>> Matias
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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