Boost C++ Libraries: Ticket #5342: find_ptr (find wrapper) https://svn.boost.org/trac10/ticket/5342 <p> Could you add a find wrapper to ptr (unordered) map that returns mapped_type* instead of an iterator (and NULL if not found)? </p> <p> The same could be provided for the other containers, but there it's less useful. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5342 Trac 1.4.3 Thorsten Ottosen Thu, 31 Mar 2011 20:15:02 GMT <link>https://svn.boost.org/trac10/ticket/5342#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5342#comment:1</guid> <description> <p> Hi </p> <p> what about </p> <blockquote> <p> map.at_ptr( key ); </p> </blockquote> <p> ? </p> <p> Anyway, this should be hard to code a small function that does what you want, so I'm not too happy about adding this. </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Sat, 02 Apr 2011 11:54:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5342#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5342#comment:2</guid> <description> <p> Hi Thorsten, </p> <p> Why at()? at() returns a reference while the requested functionality is meant as a replacement for find(). </p> <blockquote class="citation"> <p> Anyway, this should be hard to code a small function that does what you want </p> </blockquote> <p> It's easy, indeed. But it's so useful that IMO it should be part of the lib itself. </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Sat, 09 Apr 2011 13:18:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5342#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5342#comment:3</guid> <description> <p> Actually, a find_ref() would be nice too. It'd return a reference and require the key to exist. </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Fri, 07 Oct 2011 13:17:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5342#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5342#comment:4</guid> <description> <p> You're right, this can be done with non-member functions: </p> <pre class="wiki"> template &lt;class T, class U&gt; typename T::value_type::second_type* find_ptr(T&amp; c, U v) { typename T::iterator i = c.find(v); return i == c.end() ? NULL : &amp;i-&gt;second; } template &lt;class T, class U&gt; const typename T::value_type::second_type* find_ptr(const T&amp; c, U v) { typename T::const_iterator i = c.find(v); return i == c.end() ? NULL : &amp;i-&gt;second; } template &lt;class T, class U&gt; typename T::value_type::second_type find_ptr2(T&amp; c, U v) { typename T::iterator i = c.find(v); return i == c.end() ? NULL : i-&gt;second; } template &lt;class T, class U&gt; const typename T::value_type::second_type find_ptr2(const T&amp; c, U v) { typename T::const_iterator i = c.find(v); return i == c.end() ? NULL : i-&gt;second; } </pre><p> Now the hard part is to find a Boost lib that'd like to adopt these functions. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 07 Oct 2011 14:28:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5342#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5342#comment:5</guid> <description> <p> I think a natural place would be the pointer containers. </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Fri, 07 Oct 2011 14:32:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5342#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5342#comment:6</guid> <description> <p> Why? It's useful for normal map and unordered_map too. </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Wed, 14 Mar 2012 14:02:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5342#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5342#comment:7</guid> <description> <p> <sup> </sup></p> </description> <category>Ticket</category> </item> </channel> </rss>