Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-04 07:37:25


Arkadiy Vertleyb wrote:
> "Thorsten Ottosen" <nesotto_at_[hidden]> wrote
>> "Arkadiy Vertleyb" <vertleyb_at_[hidden]> wrote
>>> "Thorsten Ottosen" <nesotto_at_[hidden]> wrote
>>>> "Arkadiy Vertleyb" <vertleyb_at_[hidden]> wrote in message
>>
>>>> I don't get this. Surely one of the functions would be a better
>>>> match than the others and hence called.
>>>
>>> How is
>>>
>>> namespace MyNamespace
>>> {
>>> template<class T> end(const T&);
>>> }
>>>
>>> is better match than
>>>
>>> namespace YourNamespace
>>> {
>>> template<class T> end(const T&);
>>> }
>>> ?
>>>
>>> And now:
>>>
>>> MyNamespace::Foo<YourNamespace::Bar> obj;
>>> end(obj); // ?????
>>
>> Why would any function but the primary template be taking
>> a const T& param, that is, why don't your
>> YourNamespace::end() refer to some class in YourNamespace?
>
> Because one may have many unrelated templates that support the same
> concept. Consider your range library. What if one wants to write
> end() that is good for any std container?

The above is not a proper use of ADL. It's similar to

namespace MyNamespace
{
        template<class T> T operator-(const T&);
}

namespace YourNamespace
{
    template<class T> T operator-(const T&);
}

This would obviously break -x, when x has both MyNamespace and YourNamespace
as associated namespaces. Not only that; the definition in MyNamespace can
break -x by itself, when x has an unary operator- that is reachable via a
conversion. Yet few people qualify their operators or provide class
templates as customization points. A disaster waiting to happen, surely.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net