31 Jan
2016
31 Jan
'16
5:07 a.m.
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.