Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-01-14 11:08:11


Peter Dimov wrote:
>
> From: "Daniel Frey" <daniel.frey_at_[hidden]>
> > I fail to see the problem. The similarity is IMHO helpful, as both
> > deduce the type to generate from their parameters.
>
> make_X(args) is typically equivalent to X<...>(args). However, make_shared
> is not equivalent to the corresponding constructor. The constructor throws
> an exception when the argument has expired(), and make_shared returns an
> empty shared_ptr.

Which is surprising, at least to me. OK, I'm sure it's documented, but
documentation aside the code (and the interface) should speak for
itself. You seem to think that the function's name is the reason for
this surprise, but I don't think that any name will do in this case. The
problem is that from a semantic point of view, this function will
construct a smart pointer with a type, which is deduced from the
function's argument. The argument's value is only taken if it is not
expired, else the default value will be taken. get_shared_ptr doesn't
express this to me and I can hardly imagine that any identifier will do.
Thus, I'd leave things as they are :)

> > 'get' implies (at least to me), that it only fetches a pointer/reference
> > to something which already exists.
>
> In a way, this is exactly what make_shared/get_shared_ptr does; it fetches a
> pointer to something which already exists, the object.

..or an empty pointer if the object exists, but has expired.

Regards, Daniel

-- 
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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