title: Function overload resolution with {}
body: <p>So our C++ library lets users pass in lists of values wrapped in classes with variadic constructors so the lengths of these lists can be checked at compile time. I'm trying to add some new functionality by adding new overloaded functions. However, the 'wrong' overload is being called when I pass a zero-length array of parameters e.g. {}. The following minimal example illustrates the issue:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  class EmptyList
  {
  public:
      template&lt;typename... T&gt;
      EmptyList(T&amp;&amp;... vals)
      {
          static_assert(sizeof...(vals) == 0, "Wrong number of values");
      }
  
      std::vector&lt;double&gt; getValues() const { return {}; }
  };
  
  void testVector(int *a, std::vector&lt;double&gt; b)
  {
      std::cout &lt;&lt; "Vector: A (" &lt;&lt; a &lt;&lt; ")" &lt;&lt; std::endl;
  }
  
  void testVector(std::vector&lt;double&gt; a, std::vector&lt;double&gt; b)
  {
      std::cout &lt;&lt; "Vector: B" &lt;&lt; std::endl;
  }
  
  void testInitList(int *a, std::initializer_list&lt;double&gt; b)
  {
      std::cout &lt;&lt; "Init list: A (" &lt;&lt; a &lt;&lt; ")" &lt;&lt; std::endl;
  }
  
  void testInitList(std::initializer_list&lt;double&gt; a, std::initializer_list&lt;double&gt; b)
  {
      std::cout &lt;&lt; "Init list: B" &lt;&lt; std::endl;
  }
  
  void testEmptyList(int *a, const EmptyList &amp;b)
  {
      std::cout &lt;&lt; "Empty list: A (" &lt;&lt; a &lt;&lt; ")" &lt;&lt; std::endl;
  }
  
  void testEmptyList(const EmptyList &amp;a, const EmptyList &amp;b)
  {
      std::cout &lt;&lt; "Empty list: B" &lt;&lt; std::endl;
  }
  
  int main()
  {
      testVector({}, {});
      testInitList({}, {});
      testEmptyList({}, {});
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>Vector: A (0)
  Init list: B
  Empty list: A (0)
  </code></pre>
  
  <p>Not only does the overloading behaviour seems weird, but there seems to be some sort of compiler special case for <code>std::initializer_list</code> making it behave differently to both my class and <code>std::vector</code>. Is there any way of working around this so the function overload taking my class is chosen over the one taking the pointer?</p>