Boost logo

Boost Users :

Subject: Re: [Boost-users] Turning Boost.Multi-Index ordered_non_unique index into ordered_unique one, with custom comparator
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2016-03-03 08:12:34


On Thu, Mar 3, 2016 at 2:06 PM, Joaquin M LópezMuñoz <joaquin_at_[hidden]> wrote:

> Dominique Devienne <ddevienne <at> gmail.com> writes:
> > On Thu, Mar 3, 2016 at 10:21 AM, Joaquin M LópezMuñoz <joaquin <at>
> > But can we do better? If like in any initial email, you take into account
> > that the to-be-indexed int is part of a larger struct with other fields,
> > which can be used to "break ties" between elements who's index
> > match the "puncture"?
> >
> > [...]
> >
> > struct entry {
> > int uid; // real uuid in reality, but enough for our needs here
> > int occurence; // the field to be indexed, uniquely "except for -1"
> > };
>
> OK, yes, we can do something with that. What you want is unique sorting
> by occurrence, except when occurrence==-1 in which case you want to
> (uniquely) sort lexicographically on uid. This *is* indeed a SWO, [...]

Thank you for confirming what I suspected.

[...] Thanks to the overloads of entry_occurrence_less::operator()
> we can lookup by occurrence as if we were using
> member<entry,int,&entry::occurence>:
>

This is the part I was missing, and struggling with.
Seems simple, in hindsight :)

> I think this suits exactly your needs, please report back otherwise.

Thank you so much for your help Joaquin. (and for BMI of course! My
favorite container!!!)

This is exactly what I was looking for. Encore merci, --DD



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