|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-10-16 07:43:50
David M. Jones wrote:
> I ran into a situation (see my "smart list" post on the boost users
> group) where I wanted to create a custom allocator whose pointer
> typedef is boost::shared_ptr. In other words, the code would look
> something like:
>
> template <typename T>
> class my_allocator
> {
> public:
> typedef boost::shared_ptr<T> pointer;
> };
>
> The problem with doing this is that boost::shared_ptr<T> does not
> have the same "interface" as the equalivalent raw pointer type T*. (I
> use the term interface in the generic programming/template sense; not
> in the object oriented sense.) One example is that there is no
> operator= on boost::shared_ptr that takes a raw pointer; instead
> reset() must be used.
Raw pointers don't necessarily have an operator= that takes another kind of
raw pointer. For example, T __near * cannot be assigned T*, only itself.
Similarly, shared_ptr<T> cannot be assigned T*, only itself.
If a component tries to assign a T* to allocator<T>::pointer, it is broken
WRT nonstandard pointers.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk