<!DOCTYPE html><html lang='en'><head><title>[dcl.type.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'>9</a> Declarations <a class='abbr_ref' href='./#dcl.dcl'>[dcl.dcl]</a></h1><h2 ><a class='secnum' style='min-width:88pt'>9.1</a> Specifiers <a class='abbr_ref' href='dcl.spec#dcl.type.class.deduct'>[dcl.spec]</a></h2><h3 ><a class='secnum' style='min-width:103pt'>9.1.7</a> Type specifiers <a class='abbr_ref' href='dcl.type#class.deduct'>[dcl.type]</a></h3><h4 ><a class='secnum' style='min-width:118pt'>9.1.7.6</a> Deduced class template specialization types <a class='abbr_ref'>[dcl.type.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/declarations.tex#L1899'>#</a></div><div id='1.sentence-1' class='sentence'>If a placeholder for a deduced class type
appears as a <i ><a href='dcl.spec#nt:decl-specifier'>decl-specifier</a></i>
in the <i ><a href='dcl.spec#nt:decl-specifier-seq'>decl-specifier-seq</a></i>
of an initializing declaration (<a href='dcl.init'>[dcl.init]</a>) of a variable,
the placeholder is replaced by the return type
of the function selected by overload resolution
for class template deduction (<a href='over.match.class.deduct'>[over.match.class.deduct]</a>)<a class='hidden_link' href='#1.sentence-1'>.</a></div> <div id='1.sentence-2' class='sentence'>If the <i ><a href='dcl.spec#nt:decl-specifier-seq'>decl-specifier-seq</a></i>
is followed by an <i ><a href='dcl.decl#nt:init-declarator-list'>init-declarator-list</a></i>
or <i ><a href='class.mem#nt:member-declarator-list'>member-declarator-list</a></i>
containing more than one <i ><a href='dcl.decl#nt:declarator'>declarator</a></i>,
the type that replaces the placeholder shall be the same in each deduction<a class='hidden_link' href='#1.sentence-2'>.</a></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/declarations.tex#L1913'>#</a></div><div id='2.sentence-1' class='sentence'>A placeholder for a deduced class type
can also be used
in the <i ><a href='dcl.type#nt:type-specifier-seq'>type-specifier-seq</a></i>
in the <i ><a href='expr.new#nt:new-type-id'>new-type-id</a></i> or <i ><a href='dcl.name#nt:type-id'>type-id</a></i>
of a <i ><a href='expr.new#nt:new-expression'>new-expression</a></i> (<a href='expr.new'>[expr.new]</a>),
as the <i ><a href='dcl.type.simple#nt:simple-type-specifier'>simple-type-specifier</a></i>
in an <a href='expr.type.conv'>explicit type conversion (functional notation)</a>,
or
as the <i ><a href='dcl.type#nt:type-specifier'>type-specifier</a></i> in the <i ><a href='dcl.fct#nt:parameter-declaration'>parameter-declaration</a></i>
of a <i ><a href='temp.param#nt:template-parameter'>template-parameter</a></i> (<a href='temp.param'>[temp.param]</a>)<a class='hidden_link' href='#2.sentence-1'>.</a></div> <div id='2.sentence-2' class='sentence'>A placeholder for a deduced class type
shall not appear in any other context<a class='hidden_link' href='#2.sentence-2'>.</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/declarations.tex#L1927'>#</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> container <span class='curlybracket'>{</span>
    container<span class='parenthesis'>(</span>T t<span class='parenthesis'>)</span> <span class='curlybracket'>{</span><span class='curlybracket'>}</span>
    <span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> Iter<span class='anglebracket'>&gt;</span> container<span class='parenthesis'>(</span>Iter beg, Iter end<span class='parenthesis'>)</span>;
<span class='curlybracket'>}</span>;
<span class='keyword'>template</span><span class='anglebracket'>&lt;</span><span class='keyword'>class</span> Iter<span class='anglebracket'>&gt;</span>
container<span class='parenthesis'>(</span>Iter b, Iter e<span class='parenthesis'>)</span> <span class='operator'>-</span><span class='anglebracket'>&gt;</span> container<span class='anglebracket'>&lt;</span><span class='keyword'>typename</span> std<span class='operator'>:</span><span class='operator'>:</span>iterator_traits<span class='anglebracket'>&lt;</span>Iter<span class='anglebracket'>&gt;</span><span class='operator'>:</span><span class='operator'>:</span>value_type<span class='anglebracket'>&gt;</span>;
std<span class='operator'>:</span><span class='operator'>:</span>vector<span class='anglebracket'>&lt;</span><span class='keyword'>double</span><span class='anglebracket'>&gt;</span> v <span class='operator'>=</span> <span class='curlybracket'>{</span> <span class='comment'>/* ... */</span> <span class='curlybracket'>}</span>;

container c<span class='parenthesis'>(</span><span class='literal'>7</span><span class='parenthesis'>)</span>;                         <span class='comment'>// OK, deduces <span class='tcode_in_codeblock'>int</span> for <span class='tcode_in_codeblock'>T</span></span>
<span class='keyword'>auto</span> d <span class='operator'>=</span> container<span class='parenthesis'>(</span>v<span class='operator'>.</span>begin<span class='parenthesis'>(</span><span class='parenthesis'>)</span>, v<span class='operator'>.</span>end<span class='parenthesis'>(</span><span class='parenthesis'>)</span><span class='parenthesis'>)</span>; <span class='comment'>// OK, deduces <span class='tcode_in_codeblock'>double</span> for <span class='tcode_in_codeblock'>T</span></span>
container e<span class='curlybracket'>{</span><span class='literal'>5</span>, <span class='literal'>6</span><span class='curlybracket'>}</span>;                      <span class='comment'>// error, <span class='tcode_in_codeblock'>int</span> is not an iterator</span>
</pre> —<span style='white-space:nowrap'> </span><i>end example</i></div><span style='white-space:nowrap'> </span>]</div>  </div></div></body></html>