Boost C++ Libraries: Ticket #3249: ptr_list of const items https://svn.boost.org/trac10/ticket/3249 <p> My code will not compile when I have a ptr_list of const abstract classes (i.e: boost::ptr_list&lt;const abstract_class&gt;). When I remove the const keyword, the code compiles and works fine. I'm using gcc 4.3 on Ubuntu GNU/Linux. </p> <p> Does the list need to be able to manipulate its items and therefore they can't be const? Or is it some bug? I noticed this line in the output: </p> <p> invalid conversion from ‘const void*’ to ‘void*’ </p> <p> leading me to believe that it can't take consts. If it indeed can't take consts, you should mention it in the documentation or faq for ptr_container. </p> <p> Thanks, Matthew A. Todd </p> <p> Here is the output from the compiler: </p> <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:42: instantiated from here /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp:183: error: invalid conversion from ‘const void*’ to ‘void*’ /usr/include/boost/ptr_container/ptr_sequence_adapter.hpp:183: 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> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3249 Trac 1.4.3 matcatprg@… Tue, 07 Jul 2009 15:59:15 GMT attachment set https://svn.boost.org/trac10/ticket/3249 https://svn.boost.org/trac10/ticket/3249 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">main.cpp</span> </li> </ul> <p> sample code </p> Ticket anonymous Tue, 07 Jul 2009 19:24:03 GMT <link>https://svn.boost.org/trac10/ticket/3249#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3249#comment:1</guid> <description> <p> I have implemented initial support for it in trunk. Play around and let me know what you think. </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <author>matcatprg@…</author> <pubDate>Tue, 07 Jul 2009 20:19:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3249#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3249#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3249#comment:1" title="Comment 1">anonymous</a>: </p> <blockquote class="citation"> <p> I have implemented initial support for it in trunk. Play around and let me know what you think. </p> <p> -Thorsten </p> </blockquote> <p> assuming that this: <a class="ext-link" href="https://svn.boost.org/svn/boost/trunk/boost/ptr_container/"><span class="icon">​</span>https://svn.boost.org/svn/boost/trunk/boost/ptr_container/</a> is the correct repository, the compiler can't find push_back(), push_front(), begin(), and end(). E.g: ‘class boost::ptr_list&lt;BASE, boost::heap_clone_allocator, std::allocator&lt;void*&gt; &gt;’ has no member named ‘begin’ </p> <p> I didn't reinstall the entire library, but just downloaded ptr_container and used rest of old library. I don't think this is problematic b/c I tested 1.39.0 the same way and it works fine. </p> <p> Just to make sure that the const issue isn't one that was fixed by 1.39.0, I tested it as well and it has the same problem w/ ptr_list not compiling w/ const items. </p> <p> I should mention that in the code where I'm using ptr_list I've already switched over to non-const items in ptr_list. (B/c of abstraction there isn't a way to accidentally tweak the internals of the object, but const would be the theoretical ideal) </p> <p> Before you go changing code, are the objects in ptr_list supposed to be non-const by design? </p> <p> Matthew A. Todd </p> </description> <category>Ticket</category> </item> <item> <dc:creator>thorsten</dc:creator> <pubDate>Tue, 07 Jul 2009 20:27:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3249#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3249#comment:3</guid> <description> <p> Hi matthew, </p> <p> Please download the whole thing and let it replace the old. </p> <p> Also always state which compiler you are using. </p> <p> No, it was an implementation defect that you could not use const object. The case didn't occur to me, before you and others wanted to use it with const objects. </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <author>matcatprg@…</author> <pubDate>Tue, 07 Jul 2009 22:25:55 GMT</pubDate> <title>status changed; keywords, resolution set https://svn.boost.org/trac10/ticket/3249#comment:4 https://svn.boost.org/trac10/ticket/3249#comment:4 <ul> <li><strong>keywords</strong> ptr_list const added </li> <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> Downloaded entire library and replaced old. </p> <p> Tested in two projects, one I had attached when creating this ticket and another one. Both worked splendidly. </p> <p> I must say, I'm really impressed. </p> <p> Matthew A. Todd </p> Ticket