Boost logo

Boost :

From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2003-11-14 15:06:59


David Abrahams wrote:
> 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());

I might be mistaken, but that shouldn't compile should it? This should
fail due to ambiguity, which isn't really an ADL problem in this case
since my::clone() wasn't meant to be found.

-- 
Daniel Wallin

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