|
Boost Users : |
Subject: Re: [Boost-users] Turning Boost.Multi-Index ordered_non_unique index into ordered_unique one, with custom comparator
From: Joaquin M LópezMuñoz (joaquin_at_[hidden])
Date: 2016-03-03 04:21:26
Dominique Devienne <ddevienne <at> gmail.com> writes:
>
> I would like to support a slightly unusual use-case.
> We have a class with a integer member, and a BMI container for
> instances of this class.
>
> That member is supposed to be unique, *except* for a special "invalid"
> value (-1), which several instances can use.
>
> Right now, we use an ordered_non_unique index, because of the -1's,
> but that leaves the door open for other duplicate "valid" values,
> which should be forbidden.
>
> So my question is whether one can index this member uniquely, thanks to
> a custom comparator, such that the comparator does not violate the
> usual strict-weak-ordering requirement of ordered containers?
Steven's answer is, as always, correct, and we can leav¥Ð
ÐÑ¡
и Õа)¥å½ÔÝ
¹ÐѼٹÑÕÉ¥¹Ñ¼Õ¹¡
Éѱ
¹Ì¸¸¸()MÕÁÁ½ÍÝÕÍÑ¡½±±½Ý¥¹è((ѵÁ±
ÑñÑåÁ¹
µP±PÁÕ¹ÑÕÉø(ÍÑÉÕÐÁÕ¹ÑÕÉ}±ÍÌ(ì(½½°½ÁÉ
Ñ½È ¤¡½¹ÍÐPà±½¹ÍÐP䥽¹ÍÐ(ì(¥¡àôõÁÕ¹ÑÕÉäôõÁÕ¹ÑÕÉ¥ÉÑÕɸÑÉÕì(ÉÑÕɸàñäì(ô(ôì((ÕÍ¥¹ÍÐõ½½ÍÐèéµÕ±Ñ¥}¥¹á}½¹Ñ
¥¹Èð(¥¹Ð°(¥¹á}äð(½ÉÉ}Õ¹¥ÅÕñ¥¹Ñ¥Ñäñ¥¹Ðø±ÁÕ¹ÑÕÉ}±ÍÌñ¥¹Ð°´Äøø(ø(øì()¥ÍÐÑ¡¥¹Ñ¼¹½Ñ¥¥ÌèÁÕ¹ÑÕÉ}±ÍÌñ¥¹Ð°´Äø¥Ì©¹½Ð¨ÍÑÉ¥ÐÝ
¬)½ÉÉ¥¹¸½È¥¹ÍÑ
¹°¥Ð¥Ì¹½Ð¥Éɱá¥Ù
Ìèé½ÁÉ
Ñ½È ¤ ´Ä°´Ä¤ôõÑÉÕ¸) ÕÐ¥ÝÝÉ¥Ñè((ÍÐÌõì´Ì°´È°´Ä°À°À°Ä°´Ä°È°Ì°´Ä°Ð°Ô°´Ä°Ø°Ü°´Ä°à°ä°ä°´Åôì(½È¡¥¹ÐàéÌ¥ÍÑèé½ÕÐðñàððì()Ñ¡Ñ¡¥¹Íµ¥¹±äݽÉÌ
¹ÁÉ¥¹ÑÌ((´Ì´È´Ä´Ä´Ä´Ä´Ä´ÄÀÄÈÌRbrOÛÜÝ][R[^Z]\Â\ÈYXXÚ]ÈLHÈH[Ù\Y\È\ÜÈ][Ý\L\È[XYB[HÛÛZ[\[Ù\[ÛÛÜÙÛÜÜËÛÚÝ\\È[ÜHYXÝ[È[K[ÝHØ[\YH]ËÝÙ\ØÝ[
LJOO\ËÝÙ\ØÝ[
BË\\ØÝ[
LJOO\Ë\\ØÝ[
LB]\ËÛÚÚ[È\ÜLHZ]\È\ÈYHL\È\HÝ]Z]H\KÚXÚ\È
[ÛÛYHÙ[ÙJHÛÛÚ\Ý[Ú]HXÝ]L\È]\ÛÛ\\H[ÙHÈ[\Ù[\ËÝH]ÜËÝÙ\ØÝ[
LJKË\\ØÝ[
LJJH\ÈÝHÜ\[ÙH
B[XÙY\ÈHYÚ[[ÊK\]X[Ü[ÙH[ÛÈZ]\ÈÙNË\]X[Ü[ÙJLJOO\ÝXZÙWÜZ\ËÝÙ\ØÝ[
KËÝÙ\ØÝ[
BÚXÚ\È]X\ÝH[Y[ÙH
]ÝHØ[YH\ÂÝXZÙWÜZ\ËÝÙ\ØÝ[
LJKË\\ØÝ[
LJJH\ÈÝX\[YY the
documentation).
Lookup for values other than -1 behaves perfectly, as it is only when
invoking operator()(-1,-1) that strict weak ordering properties are
violated. If you're able to live in a state of undefined behavior and
cope with the oddities described above, well, you might take advantage of
this.
JoaquÃn M López Muñoz
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