Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost bimap]- question on use of optionalsorting predicate for set_of declarations
From: Matias Capeletto (matias.capeletto_at_[hidden])
Date: 2009-11-30 14:44:23


>> "The thing is that you are using the left view of the bimap, and not
>> the one you have customized. Try using the right view map, it should
>> work as you expect."

On Sat, Nov 28, 2009 at 2:37 AM, Curtis Himel <chimel_at_[hidden]> wrote:
> I didn't understand why switching views would work, and it didn't do what I wanted.
> (I tried it anyway.)  If I use the right view, then I'm looking up the multiset ints with
> a unique short, right?  I want to go the other way- I want to look up a sorted
> range of unique shorts from the right side with a non-unique int from the left side.
> I might have misunderstood you, but I don't see how using the right view works there.

Ok, I think I have understood you. If your data looks like:

int(1000) --- short(6)
int(1000) --- short(7)
int(1000) --- short(8)

int(2000) --- short(1)
int(2000) --- short(2)
int(2000) --- short(3)

int(3000) --- short(14)
int(3000) --- short(16)

You want to be able to get 1,2,3 in that order when looking with 2000.
Is that right?
Both sets of the bimaps (the ints, and the shorts in your case) works
separately, exactly as with standard map, your comparison function can
not take into account the values of the other set. Imagine trying to
achieve what you want with:

std::unordered_map< int, short, ... >

So it is not possible to get the data as you want using the left or
the right views that mimics the standard map behaviour. However
Boost.Bimap gives you one more view that takes both sides into
account. Please read about it here:

http://tinyurl.com/boost-bimap-coll-of-relations

You will need something like:

boost::bimap< int, short, set_of_relations< compare_two_relations > >

The compare_two_relations will compare the ints and if they are equal,
the shorts
( ra.left < rb.left or ( ra.left == rb.left && ra.right < rb.right ) )

If this abstraction does not work for you, because for example you do
not the left and right views to mimic the standard maps you may have
to reconsider using Boost.MultiIndex instead.

Best 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