Boost logo

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>> 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˜ä¥½¹ÍÐ(€€€ì(€€€€€€¥˜¡àôõÁÕ¹ÑÕÉ”˜™äôõÁÕ¹ÑÕÉ”¥É•ÑÕɸÑÉÕ”ì(€€€€€€É•ÑÕɸàñäì(€€€ô(€ôì((€ÕÍ¥¹œÍ•Ðõ‰½½ÍÐèéµÕ±Ñ¥}¥¹‘•á}½¹Ñ…¥¹•Èð(€€€¥¹Ð°(€€€¥¹‘•á•‘}‰äð(€€€€€½É‘•É•‘}Õ¹¥ÅÕ”ñ¥‘•¹Ñ¥Ñäñ¥¹Ðø±ÁÕ¹ÑÕÉ•‘}±•ÍÌñ¥¹Ð°´Äøø(€€€€ø(€€øì()¥ÍЁѡ¥¹œÑ¼¹½Ñ¥”¥ÌèÁÕ¹ÑÕÉ•‘}±•ÍÌñ¥¹Ð°´Äø¥Ì€©¹½Ð¨„ÍÑÉ¥ÐÝ•…¬)½É‘•É¥¹œ¸½È¥¹ÍÑ…¹”°¥Ð¥Ì¹½Ð¥ÉÉ•™±•á¥Ù”…Ì€èé½Á•É…ѽȠ¤ ´Ä°´Ä¤ôõÑÉÕ”¸) ÕЁ¥˜Ý”Ýɥєè((€€€Í•ÐÌõì´Ì°´È°´Ä°À°À°Ä°´Ä°È°Ì°´Ä°Ð°Ô°´Ä°Ø°Ü°´Ä°à°ä°ä°´Åôì(€€€™½È¡¥¹ÐàéÌ¥Íѐè鍽ÕÐðñàððˆ€ˆì()Ñ¡”Ñ¡¥¹œÍ••µ¥¹±äÝ½É­Ì…¹ÁÉ¥¹ÑÌ((€€€€´Ì€´È€´Ä€´Ä€´Ä€´Ä€´Ä€´Ä€À€Ä€È€Ì€Rbr‚’Oˆ›ÛÜÝ “][R[™^™Z]™\˜\ÈYˆXXÚ™]È LHÈ™H[œÙ\Y\È\ÜÈ][Ý\ˆ L\È[™XYBš[ˆHÛ۝Z[™\‹‚‚’[œÙ\[ÛˆÛܝÙˆÛÜšÜËÛÚÝ\\È[Ü™HY™šXÝ[È[™Kˆ[ÝHØ[‚™\šYžH]‚ˆË›ÝÙ\—Ø›Ý[™

LŠB‚]\ËÛÚÚ[™È\›Üˆ LH™Z]™\È\ÈYˆH L\È\™H›Ý]Z]H\™KÚXÚ\È
[ˆÛÛYHÙ[œÙJHÛÛœÚ\Ý[Ú]H˜XÝ] L\È™]™\‚˜ÛÛ\\™H˜[ÙHÈ[\Ù[™\ˈ›ÝH]–ÜË›ÝÙ\—Ø›Ý[™
B™[™™XÙY\ÈH™YÚ[›š[™ÊKˆ\]X[ܘ[™ÙH[ÛÈ™Z]™\ÈÙN‚‚ˆË™\]X[ܘ[™ÙJ LJOO\ÝŽ›XZÙWÜZ\ŠË›ÝÙ\—Ø›Ý[™


LJJH\ÈÝX\˜[YY the

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

Joaquín M López Muñoz

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at