Subject: Re: [boost] temp_ptr<> - preventing use as a member
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2011-11-17 01:30:37
On Mon, Nov 14, 2011 at 11:07 AM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> On 11/13/2011 04:41 PM, Gottlob Frege wrote:
>> I'm trying to see if I can replace all raw pointers with suitable
>> smart pointers that clearly describe the pointer's lifetime, sharing,
>> For example, a pointer passed into a function, that is only valid for
>> the lifetime of the function call. A temp_ptr or callstack_ptr or ...
>> some better name.
> This sounds a lot like scoped_ptr.
>> So this pointer would need a copy constructor so it can be passed
>> along into a function (I don't think requiring a ref to the pointer
>> would be good; I'd rather pass by value).
> I don't think this is a good idea. You probably
> don't want the copy constructor to copy the
> pointee, which means that the destructor doesn't
> necessarily call delete...
I don't want to call delete in this case. It really is just a dumb
pointer. But when I hand it out, I don't want you to keep it.
Every pointer in an API has an associated lifetime guarantee - which
varies based on the situation, but typically that guarantee is only
written in comments. Can it be made part of the code?
For the "here is a pointer, it will be invalid at the end of the
function call", in debug I could probably track outstanding copies and
maybe null out the internal pointer (ie like a weak_ptr) and then
assert if they are used beyond their lifetime. Or something like
> In Christ,
> Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk