|
Boost : |
From: Ulrich Eckhardt (uli_at_[hidden])
Date: 2005-04-27 15:39:31
On Monday 25 April 2005 17:35, Pavel Chikulaev wrote:
> Example 1:
>
> We are the developer of function Foo. And we need to mark somehow that
> returned pointer is property of
> Foo internals and it shouldn't be deleted by the client function. We can
> achieve this using weak_ptr, but what if Foo internals doesn't have any
> shared_ptr's ? What to return then? Plain pointer? No Way! We need a way to
> explicitly say that we return copy of pointer that can't be deleted and no
> synchronization is needed.
First thought is to return a reference instead of a pointer. If there really
is need to sometimes return a null pointer, one could use boost::optional
with a reference.
> Example 2:
>
> We are developer of function Foo again. And now we need to mark that
> pointer argument is needed only for time of execution of Foo (it wasn't
> collected anywhere), and user cares about deallocation. How are we going to
> write such code and make it self-describing at the same time? Plain
> pointer? No Way! That would be a C-style, but we need something like
> C++-style... This time we don't have even one std or boost candidate for
> such job.
Isn't this the same thing but this time the object being passed into the
function instead of out of it? Anyhow, I think the same solution applies. For
the case of null pointers, there is even the additional possibility of
overloading.
Uli
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk