title: What is the difference between qualified and unqualified name lookup when deducting templates?
body: <p>While writing template methods, i ran into the folowing behavior, which i do not understand.</p>
  <p>I have the folowing code:</p>
  <pre class="lang-js prettyprint-override"><code>#include &lt;array&gt;
  #include &lt;iostream&gt;
  
  namespace A
  {
      template&lt;typename T&gt;
      class Bar
      {
              T Var;
      };
  }
  
  namespace B
  {
  
      template&lt;typename T&gt;
      void Foo(const T&amp; var)
      {
              std::cout &lt;&lt; &quot;default template method has been called&quot; &lt;&lt; std::endl &lt;&lt; std::endl;
      }
  
      template&lt;typename T, size_t N&gt;
      void Foo(const std::array&lt;T,N&gt;&amp; var)
      {
              std::cout &lt;&lt; &quot;Array overload has been called&quot; &lt;&lt; std::endl;
              for(auto&amp; elem : var)
              {
                  Foo(elem);
              }
      }
  
      template&lt;typename T&gt;
      void Foo(const A::Bar&lt;T&gt;&amp; var)
      {
              std::cout &lt;&lt; &quot;Bar overload has been called&quot; &lt;&lt; std::endl &lt;&lt; std::endl;
      }
  }
  
  int main()
  {
      int                        VarInt;
      A::Bar&lt;int&gt;                VarBar;
      std::array&lt;int, 1&gt;         ArrayInt;
      std::array&lt;A::Bar&lt;int&gt;, 1&gt; ArrayBar;
  
      B::Foo(VarInt);
      B::Foo(VarBar);
      B::Foo(ArrayInt);
      B::Foo(ArrayBar);
      return 0;
  }
  </code></pre>
  <p>It's output is not what i expect as with the array of Bar, the default template is called instead of the Bar overload:</p>
  <pre><code>default template method has been called
  
  Bar overload has been called
  
  Array overload has been called
  default template method has been called
  
  Array overload has been called
  default template method has been called
  
  </code></pre>
  <p>I noticed that doing the folowing enables the compiler to find the correct overloads :</p>
  <ul>
  <li>removing all namespaces or</li>
  <li>declaring all the templates prototypes before implementing them</li>
  </ul>