Opened 13 years ago
Closed 13 years ago
#3249 closed Bugs (fixed)
ptr_list of const items
Reported by: | Owned by: | Thorsten Ottosen | |
---|---|---|---|
Milestone: | Boost 1.40.0 | Component: | ptr_container |
Version: | Boost 1.35.0 | Severity: | Problem |
Keywords: | ptr_list const | Cc: |
Description
My code will not compile when I have a ptr_list of const abstract classes (i.e: boost::ptr_list<const abstract_class>). When I remove the const keyword, the code compiles and works fine. I'm using gcc 4.3 on Ubuntu GNU/Linux.
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:
invalid conversion from ‘const void*’ to ‘void*’
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.
Thanks, Matthew A. Todd
Here is the output from the compiler:
/usr/include/boost/ptr_container/ptr_sequence_adapter.hpp: In member function ‘void boost::ptr_sequence_adapter<T, VoidPtrSeq, CloneAllocator>::push_back(typename boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<T, VoidPtrSeq>, CloneAllocator>::value_type) [with T = const BASE, VoidPtrSeq = std::list<void*, std::allocator<void*> >, CloneAllocator = 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<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = void*, _Alloc = std::allocator<void*>]’
Attachments (1)
Change History (5)
by , 13 years ago
follow-up: 2 comment:1 by , 13 years ago
I have implemented initial support for it in trunk. Play around and let me know what you think.
-Thorsten
comment:2 by , 13 years ago
Replying to anonymous:
I have implemented initial support for it in trunk. Play around and let me know what you think.
-Thorsten
assuming that this: https://svn.boost.org/svn/boost/trunk/boost/ptr_container/ is the correct repository, the compiler can't find push_back(), push_front(), begin(), and end(). E.g: ‘class boost::ptr_list<BASE, boost::heap_clone_allocator, std::allocator<void*> >’ has no member named ‘begin’
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.
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.
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)
Before you go changing code, are the objects in ptr_list supposed to be non-const by design?
Matthew A. Todd
comment:3 by , 13 years ago
Hi matthew,
Please download the whole thing and let it replace the old.
Also always state which compiler you are using.
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.
-Thorsten
comment:4 by , 13 years ago
Keywords: | ptr_list const added |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Downloaded entire library and replaced old.
Tested in two projects, one I had attached when creating this ticket and another one. Both worked splendidly.
I must say, I'm really impressed.
Matthew A. Todd
sample code