title: using directive vs using declaration swap in C++
body: <p>Please refer to the code below:</p>
  
  <pre><code>#include &lt;algorithm&gt;
  
  namespace N
  {
  
      template &lt;typename T&gt;
      class C
      {
      public:
          void SwapWith(C &amp; c)
          {
              using namespace std; // (1)
              //using std::swap;   // (2)
              swap(a, c.a);
          }
      private:
          int a;
      };
  
      template &lt;typename T&gt;
      void swap(C&lt;T&gt; &amp; c1, C&lt;T&gt; &amp; c2)
      {
          c1.SwapWith(c2);
      }
  
  }
  
  namespace std
  {
  
      template&lt;typename T&gt; void swap(N::C&lt;T&gt; &amp; c1, N::C&lt;T&gt; &amp; c2)
      {
          c1.SwapWith(c2);
      }
  
  }
  </code></pre>
  
  <p>As written above, the code doesn't compile on Visual Studio 2008/2010. The error is:</p>
  
  <pre><code>'void N::swap(N::C&lt;T&gt; &amp;,N::C&lt;T&gt; &amp;)' : could not deduce template argument for 'N::C&lt;T&gt; &amp;' from 'int'.
  </code></pre>
  
  <p>However, if I comment out (1) and uncomment (2), it will compile OK. What is the difference between <code>using namespace std</code> and <code>using std::swap</code> that explains this behavior?</p>