Boost pointer containers compile errors, runtime errors, and compiler warnings

http://www.boost.org/libs/ptr_container/doc/ptr_container.html I'm currently in the middle of writing an article making the comparison between the above boost pointer containers and the following clone smart pointers: http://code.axter.com/copy_ptr.h http://code.axter.com/cow_ptr.h I'm performing my test using boost_1_33_0, and VC++ 7.1 compiler. I'm comparring vector<copy_ptr<T> > to boost::ptr_vector<T> I want to make sure that my article is accurate and complete, so I'm posting this question. When trying to compile using copy constructor for ptr_vector, I get a compile error. boost::ptr_vector<Shape> CopyViaContainerCopyConstructor(ContainerOfOriginalShapes); //Will not compileContainerType boost::ptr_vector<Shape> CopyViaContainerCopyConstructor = ContainerOfOriginalShapes; //Will not compile Is this by design, and if so, why doesn't the boost pointer container have a copy constructor like the STL containers have? Another standard STL container interface that fails to compile using ptr_container is push_back via dereferenced iterator. Example: for(it = ContainerOfOriginalShapes.begin();it != ContainerOfOriginalShapes.end();++it) CopyViaContainerForLoopIterator.push_back(*it); Is this also by designed, and if so, why? I also notice that the follow code fails at runtime. boost::ptr_vector<Shape> CopyViaContainerForLoopOp(ContainerOfOriginalShapes.size()); for(i = 0;i < ContainerOfOriginalShapes.size();++i) CopyViaContainerForLoopOp[i] = ContainerOfOriginalShapes[i]; However, if I do the following, then it works: //Try creating the right size for the container via push_back for(i = 0;i < ContainerOfOriginalShapes.size();++i) CopyViaContainerForLoopOp.push_back(Shape::AbstractFactory(SourceData[i][0], SourceData[i][1])); //Again test copy via for loop using operator[] for(i = 0;i < ContainerOfOriginalShapes.size();++i) CopyViaContainerForLoopOp[i] = ContainerOfOriginalShapes[i]; Is there a problem with the way ptr_vector gets constructed when size argument is used for constructor with out a default value? When using the VC++ 7.1 compiler, I notice I get a compile warning "resolved overload was found by argument-dependent lookup" See full warning in following link: http://code.axter.com/boost_ptr_containers/compilerwarnings.txt Warning for following code: http://code.axter.com/boost_ptr_containers/BoostPolymorphicContainerTest.cpp http://code.axter.com/boost_ptr_containers/shape.h Is this a problem with VC++ 7.1 giving a false warning, or with the ptr_vector code design? I also welcome any additional input that may be useful for the article. Thank you

Axter <boost <at> axter.com> writes:
http://www.boost.org/libs/ptr_container/doc/ptr_container.html
I'm currently in the middle of writing an article making the comparison
containers and the following clone smart pointers: http://code.axter.com/copy_ptr.h http://code.axter.com/cow_ptr.h
I'm performing my test using boost_1_33_0, and VC++ 7.1 compiler. I'm comparring vector<copy_ptr<T> > to boost::ptr_vector<T>
I want to make sure that my article is accurate and complete, so I'm posting
between the above boost pointer this question.
When trying to compile using copy constructor for ptr_vector, I get a compile
error.
boost::ptr_vector<Shape> CopyViaContainerCopyConstructor(ContainerOfOriginalShapes); //Will not compileContainerType
boost::ptr_vector<Shape> CopyViaContainerCopyConstructor = ContainerOfOriginalShapes; //Will not compile
Is this by design, and if so, why doesn't the boost pointer container have a copy constructor like the STL containers have?
Another standard STL container interface that fails to compile using
Please read the FAQ and the conventions sections. ptr_container is push_back via
dereferenced iterator. Example: for(it = ContainerOfOriginalShapes.begin();it != ContainerOfOriginalShapes.end();++it)
CopyViaContainerForLoopIterator.push_back(*it);
Is this also by designed, and if so, why?
To make it more obvious that the container takes ownership of heap allocated objects: cont.push_back( new_clone(*it) ); The idea if letting ptr_cont<T> be replacable with cont<T> turned out not to be a very important goal, and hence simplicity in the interface was better.
I also notice that the follow code fails at runtime. boost::ptr_vector<Shape> CopyViaContainerForLoopOp(ContainerOfOriginalShapes.size());
for(i = 0;i < ContainerOfOriginalShapes.size();++i)
CopyViaContainerForLoopOp[i] = ContainerOfOriginalShapes[i];
However, if I do the following, then it works:
//Try creating the right size for the container via push_back
for(i = 0;i < ContainerOfOriginalShapes.size();++i)
CopyViaContainerForLoopOp.push_back(Shape::AbstractFactory(SourceData[i][0], SourceData[i][1]));
//Again test copy via for loop using operator[]
for(i = 0;i < ContainerOfOriginalShapes.size();++i)
CopyViaContainerForLoopOp[i] = ContainerOfOriginalShapes[i];
Is there a problem with the way ptr_vector gets constructed when size argument is used for constructor with out a default value?
there is no way to specify a default agument here. Please read the documentation for the function.
When using the VC++ 7.1 compiler, I notice I get a compile warning "resolved overload was found by argument-dependent lookup"
This is a stupid warning.
I also welcome any additional input that may be useful for the article.
I'd like to see it when you're done. -Thorsten
participants (2)
-
Axter
-
Thorsten Ottosen