Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-11-14 14:28:34


Daniel Wallin <dalwan01_at_[hidden]> writes:

> Brian McNamara wrote:
>> There are a number of recent messages on this thread, and I've chosen to
>> reply "in batch".
>> Daniel Wallin:
>>
>>>Why complicate things? Just make it a generic function that uses copy
>>>construction by default, and rely on ADL and overloading instead of
>>>class specialization.
>> This strategy uses structural conformance. I want named
>> conformance.
>> (Named conformance is not as susceptible to accidental conformance.)
>
> What about tagging the clone function?
>
> struct clone_factory_tag {};
>
> template<class T>
> T* clone(clone_factory_tag, const T& x)
> {
> return new T(x);
> }
>
> ...
>
> Foo* clone(clone_factory_tag, const Foo& x)
> {
> return x.clone();
> }

I had this idea some time ago, but Peter Dimov pointed out that it
doesn't really prevent accidental ADL problems:

      namespace my {
      
         class X {};
         template <class T>
         garbage clone(T, X& x)
         {
             // not the same meaning for "clone"
         }
      }

      lib::some_generic_algorithm(my::X());

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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