"David B. Held" <dheld@codelogicconsulting.com> wrote in message news:<bjnona$s2q$1@news.astound.net>...[color=blue]
> "Kevin Goodsell" <usenet1.spamfree.fusion@neverbox.com> wrote in message
> news:xBA7b.6107$Yt.553@newsread4.news.pas.earthlin k.net...[color=green]
> > David B. Held wrote:[color=darkred]
> > > [...]
> > > On Boost (
www.boost.org), there was a discussion about
> > > a "bimap", which is a two-way map in which the value type
> > > was actually a second key type.[/color]
> >
> > Maybe I'm not thinking clearly (it's getting rather late), but it
> > seems like you could do this with a std::set where you insert
> > the two keys at the same time, and each with some kind of
> > reference to the other.
> > Wrapping it in a new class type would make it convenient to
> > use.[/color]
>
> You could do that, but it's slightly slower and has other
> undesirable properties. For instance, in the bimap, you
> can query the map to see if a key does not exist in the
> first set. How do you do that with your design? Maintaining
> invariants is tricker with your design. Keys have to be
> added and removed in pairs. Someone could make a
> mistake and create non-paired keys that would corrupt
> the map. Or maybe someone could accidentally create
> just one key. At any rate, the wrapper would be fairly
> elaborate, and it's not obvious to me that it would be any
> better (in terms of simplicity or performance) than a custom
> designed n-map.
>
> Also, a bimap supports ordered keys, and yours does not
> (at least not without a suitably complex definition of
> "reference"). Consider the case where you wish to insert
> both (a, b) and (b, c) into the map, but you wish each key
> set to be unique. How do you do this with your design?
> You can, but it gets more and more complicated. ;)
>
> Dave[/color]
Looking through boost, I coundn't find any code posted there.
I did however find a codeproject link that had the bimap
implementation.
http://www.codeproject.com/vcpp/stl/bimap.asp
Looks like a very handy class, and I'm surprise it's not in the boost
library yet.
It would be nice if they would consider adding this to the standard.
I've frequently seen users ask about the existence of such a class or
functionality in the std::map class.