title: Why doesn't C++17 template class deduction work when I supply some of the template parameters?
body: <p>C++17 has introduced <a href="http://en.cppreference.com/w/cpp/language/class_template_argument_deduction" rel="nofollow noreferrer">class template argument deduction</a>. While most of the time it's nothing more than a syntactic sugar, there are cases when it really comes to the rescue, especially in the generic code, like <a href="https://stackoverflow.com/questions/45217180/initializing-a-vector-of-auto-unknown-type-inside-a-template-function-in-c/45217923#45217923">in this case</a>.</p>
  
  <p>Another nice application of this feature is a usage of <code>std::array</code>. Indeed, now it causes much less pain, just compare these two versions:</p>
  
  <pre><code>std::array arr{ 1, 2, 3, 4, 5 }; // with C++17 template argument deduction
  std::array&lt;int, 5&gt; arr{ 1, 2, 3, 4, 5 }; // just a normal C++11 std::array
  </code></pre>
  
  <p>Indeed, once I decide to add one more element, I can just do it without explicitly changing the type to <code>std::array&lt;int, 6&gt;</code>.</p>
  
  <p>However, the following doesn't compile:</p>
  
  <pre><code>std::array arr{ 1, 2, 3.f, 4, 5 };
  </code></pre>
  
  <p>It makes sense that the template argument deduction failed, producing an error like the following:</p>
  
  <pre><code>main.cpp:7:26: error: class template argument deduction failed:
       std::array arr{2,4.,5}; // will not compile
  </code></pre>
  
  <p>However, when I tried to give a hint, it didn't fix the problem:</p>
  
  <pre><code>std::array&lt;float&gt; arr{ 1, 2, 3.f, 4, 5 }; // will not compile as well
  </code></pre>
  
  <p>Now the compiler error message states the following:</p>
  
  <pre><code>main.cpp:7:21: error: wrong number of template arguments (1, should be 2)
       std::array&lt;float&gt; arr{2,4.,5};
                      ^
  </code></pre>
  
  <p>Why is that? Why can't I provide only some of the template arguments for a class, but I can for functions?</p>