<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">&lt;<a href="mailto:joaquin@tid.es" target="_blank">joaquin@tid.es</a>&gt;</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 &lt;ddevienne &lt;at&gt; <a href="http://gmail.com" rel="noreferrer" target="_blank">gmail.com</a>&gt; writes:<br>&gt; I would like to support a slightly unusual use-case. [...]<br><br>
</span>Steven&#39;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&lt;typename T,T puncture&gt;<br>
  struct punctured_less<br>
  {<br>
    bool operator()(const T&amp; x,const T&amp; y)const<br>
    {<br>
       if(x==puncture&amp;&amp;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 &quot;break ties&quot; between elements who&#39;s index</div><div>match the &quot;puncture&quot;?</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&lt;y;<br>
    }<br>
  };<br>
<br>
  using set=boost::multi_index_container&lt;<br>
    int,<br>
    indexed_by&lt;<br>
      ordered_unique&lt;identity&lt;int&gt;,punctured_less&lt;int,-1&gt;&gt;<br>
    &gt;<br>
  &gt;;<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 &quot;except for -1&quot;</div><div>};</div><div><br></div><div>struct by_occurence{};</div><div>using bmi = boost::multi_index_container&lt;<br></div><div>  entry,</div><div>  indexed_by&lt;<br></div><div>    random_access&lt;&gt;,</div><div>    ordered_unique&lt;<br></div><div>      tag&lt;by_occurence&gt;,</div><div>      identity&lt;entry&gt;,</div><div>      magical_occurence_less&lt;entry, -1&gt;</div><div>    &gt;</div><div>  &gt;</div><div>&gt;;</div><div><br></div><div>except right now, we have,</div><div><br></div><div>    ordered_non_unique&lt;<br></div><div>      tag&lt;by_occurence&gt;,</div><div>      member&lt;entry,int,&amp;entry::occurence&gt;<br></div><div>    &gt;</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&lt;int,-1&gt; is *not* a strict weak ordering.</blockquote><div><br></div><div>Yes. And that&#39;s why I&#39;m asking whether &quot;other&quot; fields can &quot;make it better&quot; somehow.</div><div>I &quot;think&quot; lookups would be resolved then, but I&#39;m unsure that&#39;s &quot;sound&quot;. --DD</div></div></div></div>