title: Why is this call to swap() ambiguous?
body: <p>The following program</p>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;utility&gt;
  #include &lt;memory&gt;
  
  namespace my_namespace
  {
  
  
  template&lt;class T&gt;
  void swap(T&amp; a, T&amp; b)
  {
    T tmp = std::move(a);
    a = std::move(b);
    b = std::move(tmp);
  }
  
  template&lt;class T, class Alloc = std::allocator&lt;T&gt;&gt;
  class foo {};
  
  }
  
  int main()
  {
    my_namespace::foo&lt;int&gt; *a, *b;
  
    using my_namespace::swap;
  
    swap(a,b);
  
    return 0;
  }
  </code></pre>
  
  <p>causes both <code>g++</code> and <code>clang</code> to issue the following compiler error on my system:</p>
  
  <pre><code>$ clang -std=c++11 swap_repro.cpp -I.
  swap_repro.cpp:28:3: error: call to 'swap' is ambiguous
    swap(a,b);
    ^~~~
  /usr/bin/../lib/gcc/x86_64-linux-gnu/5.2.1/../../../../include/c++/5.2.1/bits/algorithmfwd.h:571:5: note: candidate function [with _Tp = my_namespace::foo&lt;int, std::allocator&lt;int&gt; &gt; *]
      swap(_Tp&amp;, _Tp&amp;)
      ^
  swap_repro.cpp:10:6: note: candidate function [with T = my_namespace::foo&lt;int, std::allocator&lt;int&gt; &gt; *]
  void swap(T&amp; a, T&amp; b)
       ^
  1 error generated.
  
  $ g++ -std=c++11 swap_repro.cpp -I.
  swap_repro.cpp: In function ‘int main()’:
  swap_repro.cpp:28:11: error: call of overloaded ‘swap(my_namespace::foo&lt;int&gt;*&amp;, my_namespace::foo&lt;int&gt;*&amp;)’ is ambiguous
     swap(a,b);
             ^
  swap_repro.cpp:28:11: note: candidates are:
  swap_repro.cpp:10:6: note: void my_namespace::swap(T&amp;, T&amp;) [with T = my_namespace::foo&lt;int&gt;*]
   void swap(T&amp; a, T&amp; b)
        ^
  In file included from /usr/include/c++/4.9/bits/stl_pair.h:59:0,
                   from /usr/include/c++/4.9/utility:70,
                   from /usr/include/c++/4.9/algorithm:60,
                   from swap_repro.cpp:1:
  /usr/include/c++/4.9/bits/move.h:166:5: note: void std::swap(_Tp&amp;, _Tp&amp;) [with _Tp = my_namespace::foo&lt;int&gt;*]
       swap(_Tp&amp; __a, _Tp&amp; __b)
       ^
  </code></pre>
  
  <p>I don't understand why <code>std::swap</code> is being considered as a candidate overload, but it has something to do with <code>foo</code>'s use of <code>std::allocator&lt;T&gt;</code>.</p>
  
  <p>Eliminating <code>foo</code>'s second template parameter allows the program to compile without error.</p>