From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2005-03-10 16:08:10
"Felipe Magno de Almeida" <felipe.almeida_at_[hidden]> wrote in message
| > yes, but this is no ordinary std::vector. std::vector is for
| > value types; boost::ptr_vector is for pointers whose life-time
| > must be managed.
| > | boost::vector<A> vector1, vector2;
| > | vector1 = vector2;
| > boost::ptr_vector don't have an assignment operator; it is not Assignable
| > CopyConstructible.
| > you must clone or release the container:
| > vector1 = vector2.clone();
| > vector1 = vector2.release();
| I see, but it makes impossible for use ptr_containers inside other
| containers. Isnt this too restrictive?
well, yes, you would have to use a pointer container.
ptr_vector< ptr_list<Foo> > vec;
vec.push_back( new ptr_list<Foo> );
when move semantics enters the langauge, they can become movable.
| Cant they be implemented in terms of these?
| There were a discussion about this before? So that I can know the
| reasons why?
I can't remember any long discussion, but I know why I made the choice.
The types stored in a pointer container need not be copyable; most
uses will be non-copyable objects or clonable objects. Neither
type of object can be copied and hence it seems wrong to
allow a container of them to be copied; it kinda hides the true nature
of the contained objects.
Moreover, copying a whole container can be really expensive; it seems better
that the distinction between copyable and clonable objects carries over to
the containers as well so users are reminded of the distinction.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk