<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 3, 2016 at 10:21 AM, Joaquin M LópezMuñoz <span dir="ltr"><<a href="mailto:joaquin@tid.es" target="_blank">joaquin@tid.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">Dominique Devienne <ddevienne <at> <a href="http://gmail.com" rel="noreferrer" target="_blank">gmail.com</a>> writes:<br>> I would like to support a slightly unusual use-case. [...]<br><br> </span>Steven's answer is, as always, correct, and we can leave it at that. But,<br> if you want to venture into uncharted lands...<br></blockquote><div><br></div><div>it always is indeed. But also terse as well, also as usual :)</div><div>I appreciate the hand-holding here Joaquin, I can definitely use it!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> Suppose we use the following:<br> <br> template<typename T,T puncture><br> struct punctured_less<br> {<br> bool operator()(const T& x,const T& y)const<br> {<br> if(x==puncture&&y==puncture)return true;<br></blockquote><div><br></div><div>But can we do better? If like in any initial email, you take into account</div><div>that the to-be-indexed int is part of a larger struct with other fields,</div><div>which can be used to "break ties" between elements who's index</div><div>match the "puncture"?</div><div><br></div><div>This is why I asked about the comparator accessing the whole element struct.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> return x<y;<br> }<br> };<br> <br> using set=boost::multi_index_container<<br> int,<br> indexed_by<<br> ordered_unique<identity<int>,punctured_less<int,-1>><br> ><br> >;<br></blockquote><div><br></div><div>Stated differently, this is closer to our actual use-case:</div><div><br></div><div>struct entry {</div><div> int uid; // real uuid in reality, but enough for our needs here</div><div> int occurence; // the field to be indexed, uniquely "except for -1"</div><div>};</div><div><br></div><div>struct by_occurence{};</div><div>using bmi = boost::multi_index_container<<br></div><div> entry,</div><div> indexed_by<<br></div><div> random_access<>,</div><div> ordered_unique<<br></div><div> tag<by_occurence>,</div><div> identity<entry>,</div><div> magical_occurence_less<entry, -1></div><div> ></div><div> ></div><div>>;</div><div><br></div><div>except right now, we have,</div><div><br></div><div> ordered_non_unique<<br></div><div> tag<by_occurence>,</div><div> member<entry,int,&entry::occurence><br></div><div> ></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">First thing to notice is: punctured_less<int,-1> is *not* a strict weak ordering.</blockquote><div><br></div><div>Yes. And that's why I'm asking whether "other" fields can "make it better" somehow.</div><div>I "think" lookups would be resolved then, but I'm unsure that's "sound". --DD</div></div></div></div>