Boost C++ Libraries: Ticket #3832: ptr_list const items https://svn.boost.org/trac10/ticket/3832 <p> Similar to ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3249" title="#3249: Bugs: ptr_list of const items (closed: fixed)">#3249</a> (<a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/3249"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/3249</a>). ptr_list has problems with const items, but works fine with non-const items. Both push_back() and push_front() cause errors. I'm using gcc/g++ 4.4.1 on Ubuntu GNU/Linux. </p> <p> Here is my compilation output (also included as an attachment for clarity): </p> <p> In file included from /usr/include/boost/ptr_container/ptr_list.hpp:19, </p> <blockquote> <p> from main.cpp:1: </p> </blockquote> <p> /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp: In member function ‘void boost::ptr_sequence_adapter&lt;T, <a class="missing wiki">VoidPtrSeq</a>, <a class="missing wiki">CloneAllocator</a>&gt;::push_back(typename boost::ptr_container_detail::reversible_ptr_container&lt;boost::ptr_container_detail::sequence_config&lt;T, VoidPtrSeq&gt;, <a class="missing wiki">CloneAllocator</a>&gt;::value_type) [with T = const BASE, <a class="missing wiki">VoidPtrSeq</a> = std::list&lt;void*, std::allocator&lt;void*&gt; &gt;, <a class="missing wiki">CloneAllocator</a> = boost::heap_clone_allocator]’: main.cpp:41: instantiated from here /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp:249: error: invalid conversion from ‘const void*’ to ‘void*’ /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp:249: error: initializing argument 1 of ‘void std::list&lt;_Tp, _Alloc&gt;::push_back(const _Tp&amp;) [with _Tp = void*, _Alloc = std::allocator&lt;void*&gt;]’ </p> <p> Again, the interesting line is: invalid conversion from ‘const void*’ to ‘void*’ </p> <p> The attached file source code, is the same as from the previous ticket. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3832 Trac 1.4.3 matcatprg@… Sun, 10 Jan 2010 20:08:20 GMT attachment set https://svn.boost.org/trac10/ticket/3832 https://svn.boost.org/trac10/ticket/3832 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> <p> test source code </p> Ticket matcatprg@… Sun, 10 Jan 2010 20:08:42 GMT attachment set https://svn.boost.org/trac10/ticket/3832 https://svn.boost.org/trac10/ticket/3832 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">errors</span> </li> </ul> <p> g++ errors </p> Ticket anonymous Sat, 06 Feb 2010 19:56:03 GMT <link>https://svn.boost.org/trac10/ticket/3832#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3832#comment:1</guid> <description> <p> Found a workaround: use boost::shared_ptr with std::list. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 08 Feb 2010 10:47:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3832#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3832#comment:2</guid> <description> <p> If you use the trunk repository, it should work just fine IICR. </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <author>matcatprg@…</author> <pubDate>Mon, 08 Feb 2010 20:49:58 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3832#comment:3 https://svn.boost.org/trac10/ticket/3832#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> The version from svn works fine. </p> <p> Did you actually change something? Or was it that I didn't have the most recent version? </p> <p> Matthew A. Todd </p> Ticket matcatprg@… Mon, 08 Feb 2010 21:14:47 GMT <link>https://svn.boost.org/trac10/ticket/3832#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3832#comment:4</guid> <description> <p> For clarification: </p> <p> I just tested release 1.42, and the same error occurs there as well. So its something that has changed since then. </p> <p> Matthew A. Todd </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 08 Feb 2010 23:12:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3832#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3832#comment:5</guid> <description> <p> Well, the problem is that I haven't comitted trunk to the release branch. </p> <p> The change is not huge, but it might require a slight update to the docs too (not that the interfaces are affected). </p> <p> The fix is basically just some meta-functions taking into account that T might be const, and if so, instantiate container&lt;const void*&gt; instead of container&lt;void*&gt;. </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 12 May 2011 08:53:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3832#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3832#comment:6</guid> <description> <p> Is there any chance you could do the same with ptr_unordered_map? Should I open a new bug? </p> </description> <category>Ticket</category> </item> <item> <author>matcatprg@…</author> <pubDate>Mon, 16 May 2011 16:48:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3832#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3832#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3832#comment:6" title="Comment 6">anonymous</a>: </p> <blockquote class="citation"> <p> Is there any chance you could do the same with ptr_unordered_map? Should I open a new bug? </p> </blockquote> <p> I'm a little busy with school at the moment, but I'd love to help. I'll go ahead and run the check once I get a chance (within next 3 or 4 weeks). </p> <p> Matthew </p> </description> <category>Ticket</category> </item> <item> <author>matcatprg@…</author> <pubDate>Fri, 10 Jun 2011 22:10:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3832#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3832#comment:8</guid> <description> <p> I tested ptr_unordered_map&lt;const char, const BASE*&gt;. The test program compiled and ran both with and with out the consts. It also worked when the mapped type wasn't a pointer (i.e: const BASE). </p> <p> For completeness, I went ahead and retested ptr_list as well. The full results are as follows: </p> <pre class="wiki">container type | trunk (72523) | 1_46_1 ------------------- | --------------- | ---------------------------------------- ptr_list | works | fails as before (fix not pushed to releases yet) ptr_unordered_map | works | works </pre><p> The only problems I had were with grokking how to use the container (my inexperience + doc vagueness) and trying to get insert() to work. Regarding the docs, more elaboration would be nice (e.g: what can be a pointer: the mapped type). </p> <p> Regarding insert(), I couldn't tell exactly what was wrong, but it didn't have anything to do with const. I ended up using the "[]" operator to do insertion (which isn't mentioned in the doc but works and appears to be part of the intended behaviour based on ptr_map_adapter.hpp) </p> <p> Let me know if you want more information or help. </p> <p> Matthew </p> </description> <category>Ticket</category> </item> <item> <dc:creator>matt</dc:creator> <pubDate>Tue, 21 Aug 2012 18:42:09 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/3832#comment:9 https://svn.boost.org/trac10/ticket/3832#comment:9 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.41.0</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Did this change ever land in the release branch? I'm still finding it with boost 1.50 installed with macports: </p> <p> <code>/opt/local/include/boost/ptr_container/ptr_sequence_adapter.hpp:249: error: invalid conversion from ‘const void*’ to ‘void*’</code> </p> <p> <code>grep "BOOST_LIB_VERSION" /opt/local/include/boost/version.hpp</code> =&gt; <code>#define BOOST_LIB_VERSION "1_50"</code> </p> <p> <code>g++ -v</code> =&gt; <code>gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)</code> </p> Ticket Marshall Clow Tue, 21 Aug 2012 20:03:06 GMT <link>https://svn.boost.org/trac10/ticket/3832#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3832#comment:10</guid> <description> <p> This compiles correctly against the trunk, but fails against the release branch. </p> <p> The error I get from clang is: </p> <pre class="wiki">release/boost/ptr_container/ptr_sequence_adapter.hpp:249:37: error: reference to type 'const value_type' (aka 'void *const') could not bind to an lvalue of type 'value_type' (aka 'const BASE *') this-&gt;base().push_back( x ); // strong, commit ^ Downloads/main.cpp:37:13: note: in instantiation of member function 'boost::ptr_sequence_adapter&lt;const BASE, std::list&lt;void *, std::allocator&lt;void *&gt;&gt;, boost::heap_clone_allocator&gt;::push_back' requested here intList.push_back(a); </pre> </description> <category>Ticket</category> </item> </channel> </rss>