Boost logo

Boost :

Subject: Re: [boost] [shared_ptr] Design question about make_shared
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2011-06-15 03:40:55

On Tue, Jun 14, 2011 at 11:56 PM, Stephan T. Lavavej
<stl_at_[hidden]> wrote:
> [Max Sobolev]
>> free functions are preferable due to decreasing code coupling:
> Actually, make_shared<T>() needs access to shared_ptr's guts, at least if the implementer takes advantage of the obvious and highly desirable optimization. They are tightly coupled to begin with.

However, the coupling between make_shared and shared_ptr is an
implementation detail. They may or may not be coupled. For example
make_shared and shared_ptr might be coupled with another internal type
that facilitates the "highly desirable optimization", but not with
each other.

In general, a member function is always coupled with a type, whereas a
free function may or may not be coupled with one or more types
(formally by specifying it as a "friend"). Using free functions, you
can choose to pay the price in terms of physical coupling to implement
a desirable optimization, or you can choose a suboptimal (in run-time
terms) but less coupled design; and that choice does not affect the
user interface.

Emil Dotchevski
Reverge Studios, Inc.

Boost list run by bdawes at, gregod at, cpdaniel at, john at