$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: David Abrahams (dave_at_[hidden])
Date: 2005-03-09 13:39:08
"Peter Dimov" <pdimov_at_[hidden]> writes:
> David Abrahams wrote:
>> "Peter Dimov" <pdimov_at_[hidden]> writes:
>>
>>> We haven't seen identifier clashes in practice either. ;-) No, g++
>>> doesn't count.
>>
>> So maybe we should put everything in the global namespace?
>
> It is actually not _that_ unreasonable to put ADL customization point 
> defaults in the global namespace and dispense with the "using" idiom. 
> Moderately unreasonable, maybe. :-)
So let's talk about that:
  template <class T>
  T* get_pointer(T*);
  namespace foo
  {
      struct A {};
      A* get_pointer(A const&);
      template <class T>
      T f(T const& x)
      {
           return get_pointer(x);
      }
  }
  namespace bar
  {
      template <class T>
      T f(T const& x)
      {
           return get_pointer(x);
      }
  }
  int x;
  int* q = bar::f(&x);
  int* p = foo::f(&x); // problem
As long as you go with the "Herb Sutter Rule" of isolating types and
their ADL functions in their own namespace, these problems disappear.
  template <class T>
  T* get_pointer(T*);
  namespace foo
  {
      namespace baz                     //
      {                                 //
          struct A {};                  // <= Here
          A* get_pointer(A const&);     //
      }                                 //
      using baz::A;                     //
      template <class T>
      T f(T const& x)
      {
           return get_pointer(x);
      }
  }
  namespace bar
  {
      template <class T>
      T f(T const& x)
      {
           return get_pointer(x);
      }
  }
  int x;
  int* q = bar::f(&x);
  int* p = foo::f(&x); Okay
IIUC, we have two^H^H^Hthree reasons for using the idiom where ADL is
dispatched to a long ugly name (e.g. adl_end, only not that name ;->)
that does the actual work:  
[Do we call this pattern the static template method?]
  1. GCC
  2. Builtin types.
  3. Default behaviors
Not sure if 2 and 3 are really the same reason; they might be.  I sure
don't want people to have to remember different techniques for
invoking these things based on whether there's a default or they apply
to builtins.
Say, wait: every ADL function with a default currently belongs to some
library, or at least to some namespace.  That's the namespace with
which we qualify the name in the using declaration!
-- Dave Abrahams Boost Consulting www.boost-consulting.com