Subject: [boost] temp_ptr<> - preventing use as a member
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2011-11-13 19:41:44
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.
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).
It would also need construction from a raw pointer, but to avoid
having a temp_ptr being kept beyond the function call, it would not
have assignment (from another temp_ptr).
To prevent constructing one via the copy constructor that will be kept
around, I can define a custom new operator but keep it private.
The only thing, I think, that I can't prevent, is construction of a
new wrapper struct that has a temp_ptr as a member (which is copy
constructed in wrapper's constructor). Can anyone think of a way to
I think anyone that goes out of their way to make a wrapper struct
gets what they deserve, so I don't really *need* to prevent all bad
uses. But I can aslo imagine someone just using it improperly inside
their class due to misunderstanding or whatever.
And thoughts on the goal of specific smart pointers for all occasions?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk