Boost logo

Boost :

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


David Abrahams wrote:
> Daniel Wallin <dalwan01_at_[hidden]> writes:
>
>
>>>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.
>
>
> I beg to differ. If it fails accidentally due to ambiguity it's
> definitely a problem that wouldn't have happened without ADL. In some
> cases there may not be a way to prevent the wrong clone from causing
> ambiguity without modifying lib, which may be out of your control.

Ok, you are right. The library could allow some control over what is
passed to clone() though, to control ADL.

    struct myXref
    {
        myXref(const lib_i_dont_control::X& x)
          : ref(x)
        {}

        const lib_i_dont_control::X& ref;
    };

    lib_i_dont_control::X* clone(clone_factory_tag, myXref x)
    {
        return x.ref.clone();
    }

    lib::some_generic_algorithm(my::X(), type<myXref>());

Maybe not so nice..

-- 
Daniel Wallin

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