<!DOCTYPE html><html lang='en'><head><title>[over.match.class.deduct]</title><meta charset='UTF-8'/><link rel='stylesheet' type='text/css' href='14882.css'/><link rel='stylesheet' type='text/css' href='expanded.css' title='Notes and examples expanded'/><link rel='alternate stylesheet' type='text/css' href='colored.css' title='Notes and examples colored'/><link rel='alternate stylesheet' type='text/css' href='collapsed.css' title='Notes and examples collapsed'/><link rel='icon' href='icon.png'/></head><body><div class='wrapper'><h1 ><a class='secnum' style='min-width:73pt'>11</a> Overloading <a class='abbr_ref' href='./#over'>[over]</a></h1><h2 ><a class='secnum' style='min-width:88pt'>11.3</a> Overload resolution <a class='abbr_ref' href='over.match#class.deduct'>[over.match]</a></h2><h3 ><a class='secnum' style='min-width:103pt'>11.3.1</a> Candidate functions and argument lists <a class='abbr_ref' href='over.match.funcs#over.match.class.deduct'>[over.match.funcs]</a></h3><h4 ><a class='secnum' style='min-width:118pt'>11.3.1.8</a> Class template argument deduction <a class='abbr_ref'>[over.match.class.deduct]</a></h4><span class='indexparent'><a class='index' id=':deduction,class_template_arguments'></a></span><div class='para' id='1'><div class='marginalizedparent'><a class='marginalized' href='#1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/overloading.tex#L1453'>#</a></div><div id='1.sentence-1' class='sentence'>When resolving a placeholder for a deduced class type (<a href='dcl.type.class.deduct'>[dcl.type.class.deduct]</a>)
where the <i ><a href='temp.names#nt:template-name'>template-name</a></i> names a primary class template <span class='texttt'>C</span>,
a set of functions and function templates is formed comprising:
<ul class='itemize'><li id='1.1'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.1'>(1.1)</a></div><div id='1.1.sentence-1' class='sentence'>If <span class='texttt'>C</span> is defined,
for each constructor of <span class='texttt'>C</span>,
a function template with the following properties:
<ul class='itemize'><li id='1.1.1'><div class='marginalizedparent' style='left:-9em'><a class='marginalized' href='#1.1.1'>(1.1.1)</a></div><div id='1.1.1.sentence-1' class='sentence'>The template parameters are the template parameters of <span class='texttt'>C</span>
followed
by the template parameters (including default template arguments) of the constructor,
if any<a class='hidden_link' href='#1.1.1.sentence-1'>.</a></div></li><li id='1.1.2'><div class='marginalizedparent' style='left:-9em'><a class='marginalized' href='#1.1.2'>(1.1.2)</a></div><div id='1.1.2.sentence-1' class='sentence'>The types of the function parameters are those of the constructor<a class='hidden_link' href='#1.1.2.sentence-1'>.</a></div></li><li id='1.1.3'><div class='marginalizedparent' style='left:-9em'><a class='marginalized' href='#1.1.3'>(1.1.3)</a></div><div id='1.1.3.sentence-1' class='sentence'>The return type is the class template specialization
designated by <span class='texttt'>C</span>
and template arguments
corresponding to the template parameters of <span class='texttt'>C</span><a class='hidden_link' href='#1.1.3.sentence-1'>.</a></div></li></ul></div></li><li id='1.2'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.2'>(1.2)</a></div><div id='1.2.sentence-1' class='sentence'>If <span class='texttt'>C</span>
is not defined or does not declare any constructors,
an additional function template derived as above
from a hypothetical constructor <span class='texttt'>C<span class='parenthesis'>(</span><span class='parenthesis'>)</span></span><a class='hidden_link' href='#1.2.sentence-1'>.</a></div></li><li id='1.3'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.3'>(1.3)</a></div><div id='1.3.sentence-1' class='sentence'>An additional function template derived as above
from a hypothetical constructor <span class='texttt'>C<span class='parenthesis'>(</span>C<span class='parenthesis'>)</span></span>,
called the <a class='hidden_link' href='#def:copy_deduction_candidate' id='def:copy_deduction_candidate'><i >copy deduction candidate</i></a><a class='hidden_link' href='#1.3.sentence-1'>.</a></div></li><li id='1.4'><div class='marginalizedparent' style='left:-7em'><a class='marginalized' href='#1.4'>(1.4)</a></div><div id='1.4.sentence-1' class='sentence'>For each <i ><a href='temp.deduct.guide#nt:deduction-guide'>deduction-guide</a></i>,
a function or function template
with the following properties:</div><div id='1.4.sentence-2' class='sentence'><ul class='itemize'><li id='1.4.1'><div class='marginalizedparent' style='left:-9em'><a class='marginalized' href='#1.4.1'>(1.4.1)</a></div><div id='1.4.1.sentence-1' class='sentence'>The template parameters, if any,
and function parameters
are those of the <i ><a href='temp.deduct.guide#nt:deduction-guide'>deduction-guide</a></i><a class='hidden_link' href='#1.4.1.sentence-1'>.</a></div></li><li id='1.4.2'><div class='marginalizedparent' style='left:-9em'><a class='marginalized' href='#1.4.2'>(1.4.2)</a></div><div id='1.4.2.sentence-1' class='sentence'>The return type
is the <i ><a href='temp.names#nt:simple-template-id'>simple-template-id</a></i>
of the <i ><a href='temp.deduct.guide#nt:deduction-guide'>deduction-guide</a></i><a class='hidden_link' href='#1.4.2.sentence-1'>.</a></div></li></ul></div></li></ul></div></div><div class='para' id='2'><div class='marginalizedparent'><a class='marginalized' href='#2'>2</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/overloading.tex#L1505'>#</a></div><div id='2.sentence-1' class='sentence'>Initialization and overload resolution are performed as described
in <a href='dcl.init'>[dcl.init]</a> and <a href='over.match.ctor'>[over.match.ctor]</a>, <a href='over.match.copy'>[over.match.copy]</a>,
or <a href='over.match.list'>[over.match.list]</a> (as appropriate for the type of initialization
performed) for an object of a hypothetical class type, where
the selected functions and function templates are considered to be the
constructors of that class type for the purpose of forming an overload
set, and the initializer is provided by the context in which class
template argument deduction was performed<a class='hidden_link' href='#2.sentence-1'>.</a></div> <div id='2.sentence-2' class='sentence'>As an exception, the first phase in <a href='over.match.list'>[over.match.list]</a>
(considering initializer-list constructors)
is omitted if the initializer list consists of
a single expression of type <span class='mathit'>cv</span> <span class='texttt'>U</span>,
where <span class='texttt'>U</span> is a specialization of <span class='texttt'>C</span> or
a class derived from a specialization of <span class='texttt'>C</span><a class='hidden_link' href='#2.sentence-2'>.</a></div> <div id='2.sentence-3' class='sentence'>If the function or function template was generated from
a constructor or <i ><a href='temp.deduct.guide#nt:deduction-guide'>deduction-guide</a></i>
that had an <i ><a href='dcl.fct.spec#nt:explicit-specifier'>explicit-specifier</a></i>,
each such notional constructor is considered to have
that same <i ><a href='dcl.fct.spec#nt:explicit-specifier'>explicit-specifier</a></i><a class='hidden_link' href='#2.sentence-3'>.</a></div> <div id='2.sentence-4' class='sentence'>All such notional constructors are considered to be
public members of the hypothetical class type<a class='hidden_link' href='#2.sentence-4'>.</a></div></div><div class='para' id='3'><div class='marginalizedparent'><a class='marginalized' href='#3'>3</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/Eelis/draft73ca144c7e48612fe72742f9f6a5ec9ad6a934d2/source/overloading.tex#L1528'>#</a></div><div id='3.example-1' class='example'>[<span style='white-space:nowrap'> </span><a class='example_link' href='#3.example-1'><span class='textit'>Example</span></a><div class='exampleBody'><span class='textit'>:</span> <pre class='codeblock'>
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> A <span class='curlybracket'>{</span>
  <span class='keyword'>explicit</span> A<span class='parenthesis'>(</span><span class='keyword'>const</span> T<span class='operator'>&amp;</span>, <span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span><span class='parenthesis'>)</span> <span class='keyword'>noexcept</span>;               <span class='comment'>// #1</span>
  A<span class='parenthesis'>(</span>T<span class='operator'>&amp;</span><span class='operator'>&amp;</span>, <span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span><span class='parenthesis'>)</span>;                                      <span class='comment'>// #2</span>
<span class='curlybracket'>}</span>;

<span class='keyword'>int</span> i;
A a1 <span class='operator'>=</span> <span class='curlybracket'>{</span> i, i <span class='curlybracket'>}</span>;    <span class='comment'>// error: explicit constructor #1 selected in copy-list-initialization during deduction,</span>
                    <span class='comment'>// cannot deduce from non-forwarding rvalue reference in #2</span>

A a2<span class='curlybracket'>{</span>i, i<span class='curlybracket'>}</span>;         <span class='comment'>// OK, #1 deduces to <span class='tcode_in_codeblock'>A&lt;int&gt;</span> and also initializes</span>
A a3<span class='curlybracket'>{</span><span class='literal'>0</span>, i<span class='curlybracket'>}</span>;         <span class='comment'>// OK, #2 deduces to <span class='tcode_in_codeblock'>A&lt;int&gt;</span> and also initializes</span>
A a4 <span class='operator'>=</span> <span class='curlybracket'>{</span><span class='literal'>0</span>, i<span class='curlybracket'>}</span>;      <span class='comment'>// OK, #2 deduces to <span class='tcode_in_codeblock'>A&lt;int&gt;</span> and also initializes</span>

<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> A<span class='parenthesis'>(</span><span class='keyword'>const</span> T<span class='operator'>&amp;</span>, <span class='keyword'>const</span> T<span class='operator'>&amp;</span><span class='parenthesis'>)</span> <span class='operator'>-</span><span class='anglebracket'>&gt;</span> A<span class='anglebracket'>&lt;</span>T<span class='operator'>&amp;</span><span class='anglebracket'>&gt;</span>;  <span class='comment'>// #3</span>
<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>explicit</span> A<span class='parenthesis'>(</span>T<span class='operator'>&amp;</span><span class='operator'>&amp;</span>, T<span class='operator'>&amp;</span><span class='operator'>&amp;</span><span class='parenthesis'>)</span> <span class='operator'>-</span><span class='anglebracket'>&gt;</span> A<span class='anglebracket'>&lt;</span>T<span class='anglebracket'>&gt;</span>;    <span class='comment'>// #4</span>

A a5 <span class='operator'>=</span> <span class='curlybracket'>{</span><span class='literal'>0</span>, <span class='literal'>1</span><span class='curlybracket'>}</span>;      <span class='comment'>// error: explicit deduction guide #4 selected in copy-list-initialization during deduction</span>
A a6<span class='curlybracket'>{</span><span class='literal'>0</span>,<span class='literal'>1</span><span class='curlybracket'>}</span>;          <span class='comment'>// OK, #4 deduces to <span class='tcode_in_codeblock'>A&lt;int&gt;</span> and #2 initializes</span>
A a7 <span class='operator'>=</span> <span class='curlybracket'>{</span><span class='literal'>0</span>, i<span class='curlybracket'>}</span>;      <span class='comment'>// error: #3 deduces to <span class='tcode_in_codeblock'>A&lt;int&amp;&gt;</span>, #1 and #2 declare same constructor</span>
A a8<span class='curlybracket'>{</span><span class='literal'>0</span>,i<span class='curlybracket'>}</span>;          <span class='comment'>// error: #3 deduces to <span class='tcode_in_codeblock'>A&lt;int&amp;&gt;</span>, #1 and #2 declare same constructor</span>

<span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>class</span> T<span class='anglebracket'>&gt;</span> <span class='keyword'>struct</span> B <span class='curlybracket'>{</span>
  <span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>class</span> U<span class='anglebracket'>&gt;</span> <span class='keyword'>using</span> TA <span class='operator'>=</span> T;
  <span class='keyword'>template</span> <span class='anglebracket'>&lt;</span><span class='keyword'>class</span> U<span class='anglebracket'>&gt;</span> B<span class='parenthesis'>(</span>U, TA<span class='anglebracket'>&lt;</span>U<span class='anglebracket'>&gt;</span><span class='parenthesis'>)</span>;
<span class='curlybracket'>}</span>;

B b<span class='curlybracket'>{</span><span class='parenthesis'>(</span><span class='keyword'>int</span><span class='operator'>*</span><span class='parenthesis'>)</span><span class='literal'>0</span>, <span class='parenthesis'>(</span><span class='keyword'>char</span><span class='operator'>*</span><span class='parenthesis'>)</span><span class='literal'>0</span><span class='curlybracket'>}</span>;         <span class='comment'>// OK, deduces <span class='tcode_in_codeblock'>B&lt;char*&gt;</span></span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div>  </div></div></body></html>