Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2911: shared_from_this free function
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-06-08 17:06:33
#2911: shared_from_this free function
-------------------------------+--------------------------------------------
Reporter: fhess | Owner: pdimov
Type: Feature Requests | Status: new
Milestone: Boost 1.39.0 | Component: smart_ptr
Version: Boost 1.38.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+--------------------------------------------
Changes (by Jonathan Wakely <jwakely.boost_at_[hidden]>):
* cc: jwakely.boost_at_[hidden] (added)
Comment:
This idea is interesting, but I don't like the name because there is no
{{{this}}} pointer in the context of a non-member function. Maybe I'm
wrong, but I regard the "this" in {{{shared_from_this}}} as referring to
{{{this}}}. How about {{{shared_from}}} instead?
{{{
X* p = ...;
shared_ptr<X> sp = shared_from(p);
}}}
It also seems odd to have a class called
{{{enable_shared_from_this_base}}} which has a base class called
{{{enable_shared_from_this}}}! I understand the reasons, but it seems
backwards at first glance.
Renaming the free function to {{{shared_from}}} means your new class could
be renamed {{{enable_shared_from}}}. Users who only want to use the free
function can derive their class X from {{{enable_shared_from}}} (and don't
need to care that calling {{{p->enable_shared_from_this()}}} returns a
{{{shared_ptr<enable_shared_from>}}} not a {{{shared_ptr<X>}}}) while
users who want to use either the free function or the existing member
function can continue to derive from {{{enable_shared_from_this<X>}}}.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/2911#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:00 UTC