Boost C++ Libraries: Ticket #9223: Alllow find(key) with key's type different from the contained value type. https://svn.boost.org/trac10/ticket/9223 <p> In a test, I have this: </p> <pre class="wiki"> struct Id { int value; }; bool operator==( const Id&amp; a, const Id&amp; b ) { return a.value == b.value; } bool operator&lt; ( const Id&amp; a, const Id&amp; b ) { return a.value &lt; b.value; } struct Event { Id id; std::string data; }; bool operator==( const Entity&amp; a, const Entity&amp; b ) { return a.id == b.id; } bool operator&lt; ( const Entity&amp; a, const Entity&amp; b ) { return a.id &lt; b.id; } bool operator==( const Id&amp; a, const Entity&amp; b ) { return a == b.id; } bool operator==( const Entity&amp; a, const Id&amp; b ) { return b == a; } </pre><p> Here value type Event can be compared to Id. Now this test can't work: </p> <pre class="wiki">boost::container::flat_set&lt;Event&gt; events; events.find( Id{42} ); // ERROR: Id isn't an Event! </pre><p> I would like this to compile because it would allow me to have a set of objects containing a state which can be overridden. In this test Event's value is it's id, but it contain associated data too which are not part of the comparison and can change when we insert new Events with the same id but different data. </p> <p> This feature looks like a recent c++ proposal: n3573 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9223 Trac 1.4.3 mjklaim@… Thu, 10 Oct 2013 12:04:29 GMT attachment set https://svn.boost.org/trac10/ticket/9223 https://svn.boost.org/trac10/ticket/9223 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">anyvalueset.hpp</span> </li> </ul> <p> Example of real-world code that would be simplified by the feature. </p> Ticket mjklaim@… Thu, 10 Oct 2013 12:05:06 GMT attachment set https://svn.boost.org/trac10/ticket/9223 https://svn.boost.org/trac10/ticket/9223 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">anyvalueset.cpp</span> </li> </ul> <p> Test of the real world example. </p> Ticket mjklaim@… Thu, 10 Oct 2013 12:09:28 GMT <link>https://svn.boost.org/trac10/ticket/9223#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9223#comment:1</guid> <description> <p> As you will see in the example attached (tests uses Google Test) the call to find allow different types of keys than the underlying value type, as expressed in the "unique_key_values" test. </p> <p> Unfortunately I had to write a custom "find" function in the AnyValueSet::<a class="missing wiki">SetOf</a> class, so that the key is used to compare directly with the value, both types being preserved. </p> <p> Fortunately, flat_set being basically a vector, it's not really a problem on performance to write the search this way. </p> <p> Anyway, I wanted to give my use case. The find function could be simplified by just providing the key to flat_set instead of having to do the search manually. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sun, 13 Oct 2013 19:07:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9223#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9223#comment:2</guid> <description> <p> C++14 will include new find functions for associative containers: </p> <p> template &lt;class K&gt; iterator find(const K&amp; x); template &lt;class K&gt; const_iterator find(const K&amp; x) const; </p> <p> "returns an iterator pointing to an element with key r such that !c(r, ke) &amp;&amp; !c(ke, r), or a_tran.end() if such an element is not found" </p> <p> The original proposal was: <a class="ext-link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3657.htm"><span class="icon">​</span>http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3657.htm</a> </p> <p> In the future, Boost.Container will try to implement C++14 features so I'll left this issue open until this feature is implemented. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Tue, 01 May 2018 13:23:29 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9223#comment:3 https://svn.boost.org/trac10/ticket/9223#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Better late than never. Commit: </p> <p> <a class="ext-link" href="https://github.com/boostorg/container/commit/48c21e3187cd95b42803efe297842b52c896090e"><span class="icon">​</span>https://github.com/boostorg/container/commit/48c21e3187cd95b42803efe297842b52c896090e</a> </p> <p> Many thanks for the report. </p> Ticket mjklaim@… Sun, 06 May 2018 20:58:15 GMT <link>https://svn.boost.org/trac10/ticket/9223#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9223#comment:4</guid> <description> <p> Thanks for your work! </p> </description> <category>Ticket</category> </item> </channel> </rss>