Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using what @Ben Voigt said in the comments on the other answer, I have gathered some relevant standard quotes:</p> <blockquote> <p>§14.5.6.2</p> <p>A function template can be overloaded with other function templates and with normal (non-template) functions. A normal function is not related to a function template (i.e., it is <strong>never considered to be a specialization</strong>), <strong>even if it has the same name and type as a potentially generated function template specialization</strong>.</p> </blockquote> <p>So that rules out function template specialisation as what you're doing, because even if two function template overloads could potentially generate the same function, it's not specialisation. So it's overloading.</p> <blockquote> <p>Such specializations are distinct functions and do not violate the one definition rule (3.2).</p> </blockquote> <p>So they're distinct functions and that's why it's not erroring.</p> <blockquote> <p>§14.5.6.2.1</p> <p>If a function template is overloaded, the use of a function template specialization* might be ambiguous because template argument deduction (14.8.2) may associate the function template specialization with more than one function template declaration.</p> </blockquote> <p>This is priming is for what we both already saw, which is that <code>in_list(a, b)</code> where <code>b</code> is an <code>initializer_list</code> appears to match both function templates.</p> <p>(*Note that "function template specialization" here doesn't mean specialising a function template, it means a function template that has been instantiated with a type. So with <code>template&lt;typename T&gt; f();</code>, <code>f&lt;int&gt;()</code> is a function template specialisation.)</p> <p>So we use what is called <em>partial ordering of overloaded function templates</em> to resolve this:</p> <blockquote> <p>Partial ordering of overloaded function template declarations is used in the following contexts to select the function template to which a function template specialization refers:</p> <p>— during overload resolution for a call to a function template specialization (13.3.3);</p> <p>— when the address of a function template specialization is taken;</p> <p>— when a placement operator delete that is a function template specialization is selected to match a placement operator new (3.7.4.2, 5.3.4);</p> <p>— when a friend function declaration (14.5.4), an explicit instantiation (14.7.2) or an explicit specialization (14.7.3) refers to a function template specialization.</p> </blockquote> <p>Ok, so that's when partial ordering is for. This is what it does:</p> <blockquote> <p>Partial ordering selects which of two function templates is more specialized than the other by transforming each template in turn (see next paragraph) and performing template argument deduction using the function type. The deduction process determines whether one of the templates is more specialized than the other. If so, the more specialized template is the one chosen by the partial ordering process.</p> </blockquote> <p>And then you get into the long and laborious process of determining which template is more specialised, which you can read about if you want, but it's really complicated and I probably don't understand it all (and plus, I don't have enough time to write about it :)).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload