Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] Interest in the missing smart pointer (that can target the stack)
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2016-01-31 00:07:31


On 1/29/2016 3:27 PM, Emil Dotchevski wrote:
>
> int main()
> {
> foo local;
> shared_ptr<foo> pl(&local,null_deleter());
> ....
> do_something(p);
> ....
> assert(pl.unique());
> }
>
> Does it look less scary now?
>

No, it still just looks like the coder wants job security to me.

I understand that the goal of the snippet is to get a handle to 'local'
which can be stored and later invalidated and this code is abusing
shared_ptr for that purpose but it's completely wrong.

It's wrong for the same reason you don't write operator==() to test for
equality and operator!=() to compute prime factorization.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk