ptr_vector problem when storing it inside a map

Hi all, I've just started looking at ptr_vector<> and got stuck on the following issue: putting a boost::ptr_vector<Simple> into a map doesn't compile. See the following test case: class Simple { public: virtual ~Simple() { } void foo() { doFoo(); } protected: virtual void doFoo() { } }; void Test() { std::map<std::string, boost::ptr_vector<Simple> > map; map["key"].push_back(new Simple); } I'm using VS2005 RC1 (8.0.50727.26) and the compiler output is as follows: 1>c:\work\3rd-party\boost\include\boost-1_33\boost/ptr_container/ptr_sequence_adapter.hpp(595) : error C2248: 'boost::ptr_container_detail::reversible_ptr_container<Config,CloneAllocator>::reversible_ptr_container' : cannot access private member declared in class 'boost::ptr_container_detail::reversible_ptr_container<Config,CloneAllocator>' 1> with 1> [ 1> Config=boost::ptr_container_detail::sequence_config<Simple,std::vector<void *,std::allocator<void *>>>, 1> CloneAllocator=boost::heap_clone_allocator 1> ] 1> c:\work\3rd-party\boost\include\boost-1_33\boost/ptr_container/detail/reversible_ptr_container.hpp(294) : see declaration of 'boost::ptr_container_detail::reversible_ptr_container<Config,CloneAllocator>::reversible_ptr_container' 1> with 1> [ 1> Config=boost::ptr_container_detail::sequence_config<Simple,std::vector<void *,std::allocator<void *>>>, 1> CloneAllocator=boost::heap_clone_allocator 1> ] 1> This diagnostic occurred in the compiler generated function 'boost::ptr_sequence_adapter<T,VoidPtrSeq,CloneAllocator>::ptr_sequence_adapter(const boost::ptr_sequence_adapter<T,VoidPtrSeq,CloneAllocator> &)' 1> with 1> [ 1> T=Simple, 1> VoidPtrSeq=std::vector<void *,std::allocator<void *>>, 1> CloneAllocator=boost::heap_clone_allocator 1> ] Can anybody shed some light on the subject? Thanks, Oleg.

Oleg Smolsky <oleg.smolsky <at> pacific-simulators.co.nz> writes:
Hi all,
I've just started looking at ptr_vector<> and got stuck on the following issue:
std::map<std::string, boost::ptr_vector<Simple> > map; map["key"].push_back(new Simple);
The problem is that no pointer container is copyable. Do std::map<std::string, boost::shared_ptr< boost::ptr_vector<Simple> > > map; or boost::ptr_map<std::string, boost::ptr_vector<Simple> > map; HTH Thorsten

Thorsten Ottosen <nesotto@cs.aau.dk> writes:
Oleg Smolsky <oleg.smolsky <at> pacific-simulators.co.nz> writes:
Hi all,
I've just started looking at ptr_vector<> and got stuck on the following issue:
std::map<std::string, boost::ptr_vector<Simple> > map; map["key"].push_back(new Simple);
The problem is that no pointer container is copyable.
Note that it was a design decision to make them noncopyable. See http://lists.boost.org/Archives/boost/2005/04/85005.php for the background. -- Dave Abrahams Boost Consulting www.boost-consulting.com

Hello Thorsten, Thorsten Ottosen wrote on 26/10/2005 at 4:04 a.m.:
I've just started looking at ptr_vector<> and got stuck on the following issue: std::map<std::string, boost::ptr_vector<Simple> > map; map["key"].push_back(new Simple); The problem is that no pointer container is copyable. Do std::map<std::string, boost::shared_ptr< boost::ptr_vector<Simple> > > map; Right, so, this is to ensure that the user understands that there is an issue copying "a vector full of pointers". IE are the pointers copied or are the objects they point to cloned? This kinda makes sense.
boost::ptr_map<std::string, boost::ptr_vector<Simple> > map; So, I'm guessing the second parameter is stored by pointer in this case? And the key is handled "by value", right?
Thanks, Oleg.

Oleg Smolsky <oleg.smolsky <at> pacific-simulators.co.nz> writes:
IE are the pointers copied or are the objects they point to cloned? This kinda makes sense.
Thanks.
boost::ptr_map<std::string, boost::ptr_vector<Simple> > map; So, I'm guessing the second parameter is stored by pointer in this case? And the key is handled "by value", right?
Right. HTH Thorsten
participants (3)
-
David Abrahams
-
Oleg Smolsky
-
Thorsten Ottosen