Boost logo

Boost :

Subject: Re: [boost] [smart_ptr] shared_ptr template type
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2009-07-15 12:31:05


Zachary Turner wrote:
> The most recent experience I had is in regards to providing custom
> validators for types in boost::program_options.
<snip>

> Another experience I had which I also made a thread about a week or so
> ago was with regards to intrusive_ptr.
<snip>

OK, I understand a little better now. In each case you want to be able
to provide different behaviour for different uses of the same type. I
agree with other posters that perhaps this is a confusion between traits
and policies. I struggle to imagine the same pseudo-pointer type
requiring two different meanings of what null is, but that may be a lack
of imagination on my part :).

> Regarding enable_if, I didn't actually think of that. But is there a
> reason that if the generic class in question uses a default traits
> class as I suggested, that a user cannot simply provide a template
> specialization of that same class that uses the class template version
> of enable_if to achieve a similar effect?

You can, but only if the author of the class template provides a spare
template parameter for this purpose defaulted to void. e.g.

template<typename Pointer, typename Enabler = void>
class pointer_policy {
  // ...
};

and I've never seen any library do that. Moreover, you *can't* do that
if the template is variadic.

John Bytheway


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