Boost C++ Libraries: Ticket #4107: ptr_map::mapped_type incorrect https://svn.boost.org/trac10/ticket/4107 <p> ptr_map::mapped_type seems incorrect. It's int* instead of int. </p> <pre class="wiki">#include &lt;boost/ptr_container/ptr_map.hpp&gt; #include &lt;map&gt; template &lt;class T, class U&gt; typename T::mapped_type* find_ptr(T&amp; c, U v) { typename T::iterator i = c.find(v); return i == c.end() ? NULL : &amp;i-&gt;second; } int main() { typedef boost::ptr_map&lt;char, int&gt; c1_t; std::map&lt;char, int&gt; c0; c1_t c1; int* p0 = find_ptr(c0, 'x'); int* p1 = find_ptr(c1, 'x'); return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4107 Trac 1.4.3 c_crickmar <chris@…> Thu, 04 Nov 2010 20:44:00 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4107#comment:1 https://svn.boost.org/trac10/ticket/4107#comment:1 <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">invalid</span> </li> </ul> <p> boost::ptr_map is not a drop in replacement for std::map. mapped_type is always a pointer, the container is designed to handle the memory management tasks of the heap allocated object. </p> Ticket anonymous Thu, 04 Nov 2010 21:10:32 GMT <link>https://svn.boost.org/trac10/ticket/4107#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:2</guid> <description> <p> I know. But isn't ptr_map designed to provide the interface of std::map as close as possible? When 'reading' ptr_map, it looks like it contains (references to) objects. So it'd be great if mapped_type reflected that. </p> </description> <category>Ticket</category> </item> <item> <author>c_crickmar <chris@…></author> <pubDate>Fri, 05 Nov 2010 13:23:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4107#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:3</guid> <description> <p> The value_type would have to be translated from std::pair&lt;Key, T*&gt; to std::pair&lt;Key, T&gt; which couldn't be done without copying T. I suppose a reference wrapper could be used but then the value type is std::pair&lt;Key, boost::reference_wrapper&lt;T&gt; &gt; which I don't think is an improvement. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Nov 2010 13:38:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4107#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:4</guid> <description> <p> I'm not sure what you're trying to say. If you look at the code example, I'm returning a pointer, so no copy is necessary. </p> </description> <category>Ticket</category> </item> <item> <author>c_crickmar <chris@…></author> <pubDate>Fri, 05 Nov 2010 13:46:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4107#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:5</guid> <description> <p> yes but you are taking the address of the value here '&amp;i-&gt;second' hence the value_type (i) would have to be std::pair&lt;Key, T&gt;. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Nov 2010 14:42:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4107#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:6</guid> <description> <p> The address operator works fine, that's not the problem. </p> </description> <category>Ticket</category> </item> <item> <author>c_crickmar <chris@…></author> <pubDate>Fri, 05 Nov 2010 15:04:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4107#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:7</guid> <description> <p> For 'second' to be T and not T*, which is required in your code fragment, it would have to be a copy of the stored T*. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 05 Nov 2010 15:12:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4107#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:8</guid> <description> <p> Why can't it be a reference to T? </p> </description> <category>Ticket</category> </item> <item> <author>c_crickmar <chris@…></author> <pubDate>Fri, 05 Nov 2010 15:34:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4107#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:9</guid> <description> <p> that would require std::pair&lt;Key, T&amp;&gt;. </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Fri, 07 Oct 2011 13:11:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4107#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4107#comment:10</guid> <description> <p> Just for the record: "T::value_type::second_type*" works. </p> </description> <category>Ticket</category> </item> </channel> </rss>