title: Is it okay to define a totally general swap() function?
body: <p>The following snippet:</p>
  
  <pre><code>#include &lt;memory&gt;
  #include &lt;utility&gt;
  
  namespace foo
  {
      template &lt;typename T&gt;
      void swap(T&amp; a, T&amp; b)
      {
          T tmp = std::move(a);
          a = std::move(b);
          b = std::move(tmp);
      }
  
      struct bar { };
  }
  
  void baz()
  {
      std::unique_ptr&lt;foo::bar&gt; ptr;
      ptr.reset();
  }
  </code></pre>
  
  <p>does not compile for me:</p>
  
  <pre><code>$ g++ -std=c++11 -c foo.cpp
  In file included from /usr/include/c++/5.3.0/memory:81:0,
                   from foo.cpp:1:
  /usr/include/c++/5.3.0/bits/unique_ptr.h: In instantiation of ‘void std::unique_ptr&lt;_Tp, _Dp&gt;::reset(std::unique_ptr&lt;_Tp, _Dp&gt;::pointer) [with _Tp = foo::bar; _Dp = std::default_delete&lt;foo::bar&gt;; std::unique_ptr&lt;_Tp, _Dp&gt;::pointer = foo::bar*]’:
  foo.cpp:20:15:   required from here
  /usr/include/c++/5.3.0/bits/unique_ptr.h:342:6: error: call of overloaded ‘swap(foo::bar*&amp;, foo::bar*&amp;)’ is ambiguous
    swap(std::get&lt;0&gt;(_M_t), __p);
        ^
  In file included from /usr/include/c++/5.3.0/bits/stl_pair.h:59:0,
                   from /usr/include/c++/5.3.0/bits/stl_algobase.h:64,
                   from /usr/include/c++/5.3.0/memory:62,
                   from foo.cpp:1:
  /usr/include/c++/5.3.0/bits/move.h:176:5: note: candidate: void std::swap(_Tp&amp;, _Tp&amp;) [with _Tp = foo::bar*]
       swap(_Tp&amp; __a, _Tp&amp; __b)
       ^
  foo.cpp:7:10: note: candidate: void foo::swap(T&amp;, T&amp;) [with T = foo::bar*]
       void swap(T&amp; a, T&amp; b)
  </code></pre>
  
  <p>Is this my fault for declaring a <code>swap()</code> function so general that it conflicts with <code>std::swap</code>?</p>
  
  <p>If so, is there a way to define <code>foo::swap()</code> so that it doesn't get hauled in by Koenig lookup?</p>