Boost logo

Boost :

From: Alan Bellingham (alan_at_[hidden])
Date: 2002-02-03 07:23:59


"Jani Kajala" <jani_at_[hidden]>:

>> Because auto_ptr<> doesn't satisfy the requirements for being a
>> std::vector<> member?
>
>Which requirement? At least I've used vectors of auto ptrs before without
>problems...

20.4.5 para 3 of the C++ Standard

"auto_ptr does not meet the CopyConstructible and Assignable
requirements for Standard Library container elements and thus
instantiating a Standard Library container with an auto_ptr results in
undefined behaviour."

auto_ptr is a very weird object - the copy constructor and assignment
operator take a non-const rhs. This means that the following should not
compile:

 typedef std::auto_ptr<int> T ;
 std::vector<T > a ;
 T t ;
 a.push_back(t) ;

whereas if the type T is just a plain pointer, there is no problem. Also
consider just copying a vector of std::auto_ptr - which vector's
elements own the pointed-to items?


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