title: Why does the order of template parameters matter to the MS C++ compiler in this example?
body: <p>The following code compiles fine in GCC but in Visual Studio it results in </p>
  
  <blockquote>
    <p>error C2782: '<code>bool contains(const T &amp;,const std::initializer_list&lt;T2&gt;</code>
    <code>&amp;)</code>' : template parameter '<code>T</code>' is ambiguous see declaration of
    '<code>contains</code>' could be '<code>const wchar_t *</code>' or       '<code>std::wstring</code>'</p>
  </blockquote>
  
  <p>It does however compile and work if the order of the template parameters is given as</p>
  
  <p><code>template&lt;typename T2, typename T&gt;</code></p>
  
  <p>Is this a compiler bug?</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;set&gt;
  #include &lt;initializer_list&gt;
  #include &lt;algorithm&gt;
  
  template&lt;typename T, typename T2&gt;
  bool contains(T const&amp; value, std::initializer_list&lt;T2&gt; const&amp; set)
  {
    return std::find(std::begin(set), std::end(set), value) != std::end(set);
  }
  
  int main(void)
  {
    std::set&lt;std::wstring&gt; values = { L"bar", L"not" };
  
    for (std::wstring val : values) {
      std::wcout &lt;&lt; "\"" &lt;&lt; val &lt;&lt; "\" ";
      if (contains(val, { L"foo", L"bar", L"baz", L"doom" })) {
        std::wcout &lt;&lt; "found" &lt;&lt; std::endl;
      }
      else {
        std::wcout &lt;&lt; "not found" &lt;&lt; std::endl;
      }
    }
  }
  </code></pre>
  
  <p>Edit: I have created a bugreport: <a href="https://connect.microsoft.com/VisualStudio/feedbackdetail/view/982338/template-parameter-order-matters">https://connect.microsoft.com/VisualStudio/feedbackdetail/view/982338/template-parameter-order-matters</a></p>