Boost logo

Boost :

From: Axter (boost_at_[hidden])
Date: 2005-11-18 08:45:17


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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk