Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-05-12 05:52:10

Currently, policy_ptr:

constains a conversion policy which determines whether or
not to contain an implicit conversion to the raw pointer via
the smart_ptr</*polcies typelist*/>::to<Referent> method:

   operator automatic_conversion_result(void) const;


         typedef typename conversion_policy::result_type

However, since smart_ptr<...>::to<Referent> is derived as:

     class smart_ptr<P1, P2, P3, P4>::to
         : public detail::policy_ptr::conversion_policy_

couldn't the automatic conversion operator just be defined
(in the case of allow_conversion) or not (in the case of
disallow conversion) in the conversion policy itself?

In addition, instead of allowing the raw pointer to escape
from the "protection" of the smart_ptr via the storage
policy's get_impl, why not delegate this decision to a
"sink" policy, which decides how the pointee is exposed to
outside use? IOW, rename the conversion policy to the sink
policy which decides whether 'operator pointer_type()' or
'get_impl' are publicly exposed. This would allow for a
"safer" smart pointer.

Along the same lines, why not allow a "source" policy which
decides the "inputs" (the CTOR args) to the smart pointer.
Currently, for smart_ptr<...>::to<Referent>, the only
"source", IIUC, is Referent*. (By source, I mean any CTOR
arguments that don't include another smart pointer ). This
would also allow for a "safer" smart pointer since the sole
source could be something like David Abraham's auto_ptr_new:

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