Opened 10 years ago

Closed 9 years ago

#7829 closed Feature Requests (fixed)

Add add_ref param to intrusive_ptr::reset

Reported by: Bruno Martinez Aguerre <bruno.uy@…> Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.52.0 Severity: Not Applicable
Keywords: intrusive_ptr Cc:

Description

intrusive_ptr::reset should have an optional bool add_ref=true parameter just as the intrusive_ptr constructor has. Currently you can call the constructor and assign, but this forces you to mention the template pointer type.

Change History (2)

comment:1 by bruno.uy@…, 10 years ago

Actually I think I prefer

template<class T> intrusive_ptr<T> take_ptr(T* t) {

return intrusive_ptr<T>(t, false);

}

from http://www.gamedev.net/topic/556405-should-i-be-using-ccomptr--boostshare_ptr-or-boostintrusive_ptr-for-com/#entry4573797

take_ptr is like a hypothetical make_intrusive, which only make sense for the add_ref=false case because raw T* is already convertible to intrusive_ptr<T> in the add_ref=true case. take_ptr as a separate function is also clearer than a false argument to the constructor, and with r-values, as efficient as reset(ptr, false) would be. If I could travel back in time I would suggest take_ptr as a friend function and getting rid of the add_ref parameter altogether.

comment:2 by Peter Dimov, 9 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.