|
2297 | 2297 | \end{codeblock}
|
2298 | 2298 | \end{example}
|
2299 | 2299 |
|
| 2300 | +\rSec3[temp.deduct.guide]{Deduction guides} |
| 2301 | +\indextext{deduction!class template argument}% |
| 2302 | + |
| 2303 | +\pnum |
| 2304 | +Deduction guides are used |
| 2305 | +when a \grammarterm{template-name} appears |
| 2306 | +as a type specifier |
| 2307 | +for a deduced class type\iref{dcl.type.class.deduct}. |
| 2308 | +Deduction guides are not found by name lookup. |
| 2309 | +Instead, when performing class template argument deduction\iref{over.match.class.deduct}, |
| 2310 | +any deduction guides declared for the class template are considered. |
| 2311 | + |
| 2312 | +\begin{bnf} |
| 2313 | +\nontermdef{deduction-guide}\br |
| 2314 | + \opt{explicit-specifier} template-name \terminal{(} parameter-declaration-clause \terminal{)} \terminal{->} simple-template-id \terminal{;} |
| 2315 | +\end{bnf} |
| 2316 | + |
| 2317 | +\pnum |
| 2318 | +\begin{example} |
| 2319 | +\begin{codeblock} |
| 2320 | +template<class T, class D = int> |
| 2321 | +struct S { |
| 2322 | + T data; |
| 2323 | +}; |
| 2324 | +template<class U> |
| 2325 | +S(U) -> S<typename U::type>; |
| 2326 | + |
| 2327 | +struct A { |
| 2328 | + using type = short; |
| 2329 | + operator type(); |
| 2330 | +}; |
| 2331 | +S x{A()}; // \tcode{x} is of type \tcode{S<short, int>} |
| 2332 | +\end{codeblock} |
| 2333 | +\end{example} |
| 2334 | + |
| 2335 | +\pnum |
| 2336 | +The same restrictions apply |
| 2337 | +to the \grammarterm{parameter-declaration-clause} |
| 2338 | +of a deduction guide |
| 2339 | +as in a function declaration\iref{dcl.fct}. |
| 2340 | +The \grammarterm{simple-template-id} |
| 2341 | +shall name a class template specialization. |
| 2342 | +The \grammarterm{template-name} |
| 2343 | +shall be the same \grammarterm{identifier} |
| 2344 | +as the \grammarterm{template-name} |
| 2345 | +of the \grammarterm{simple-template-id}. |
| 2346 | +A \grammarterm{deduction-guide} |
| 2347 | +shall be declared |
| 2348 | +in the same scope |
| 2349 | +as the corresponding class template |
| 2350 | +and, for a member class template, with the same access. |
| 2351 | +Two deduction guide declarations |
| 2352 | +in the same translation unit |
| 2353 | +for the same class template |
| 2354 | +shall not have equivalent \grammarterm{parameter-declaration-clause}{s}. |
| 2355 | + |
2300 | 2356 | \rSec3[temp.mem.class]{Member classes of class templates}
|
2301 | 2357 |
|
2302 | 2358 | \pnum
|
|
8999 | 9055 | is present in some translation unit.
|
9000 | 9056 | \end{example}
|
9001 | 9057 |
|
9002 |
| -\rSec1[temp.deduct.guide]{Deduction guides} |
9003 |
| -\indextext{deduction!class template argument}% |
9004 |
| - |
9005 |
| -\pnum |
9006 |
| -Deduction guides are used |
9007 |
| -when a \grammarterm{template-name} appears |
9008 |
| -as a type specifier |
9009 |
| -for a deduced class type\iref{dcl.type.class.deduct}. |
9010 |
| -Deduction guides are not found by name lookup. |
9011 |
| -Instead, when performing class template argument deduction\iref{over.match.class.deduct}, |
9012 |
| -any deduction guides declared for the class template are considered. |
9013 |
| - |
9014 |
| -\begin{bnf} |
9015 |
| -\nontermdef{deduction-guide}\br |
9016 |
| - \opt{explicit-specifier} template-name \terminal{(} parameter-declaration-clause \terminal{)} \terminal{->} simple-template-id \terminal{;} |
9017 |
| -\end{bnf} |
9018 |
| - |
9019 |
| -\pnum |
9020 |
| -\begin{example} |
9021 |
| -\begin{codeblock} |
9022 |
| -template<class T, class D = int> |
9023 |
| -struct S { |
9024 |
| - T data; |
9025 |
| -}; |
9026 |
| -template<class U> |
9027 |
| -S(U) -> S<typename U::type>; |
9028 |
| - |
9029 |
| -struct A { |
9030 |
| - using type = short; |
9031 |
| - operator type(); |
9032 |
| -}; |
9033 |
| -S x{A()}; // \tcode{x} is of type \tcode{S<short, int>} |
9034 |
| -\end{codeblock} |
9035 |
| -\end{example} |
9036 |
| - |
9037 |
| -\pnum |
9038 |
| -The same restrictions apply |
9039 |
| -to the \grammarterm{parameter-declaration-clause} |
9040 |
| -of a deduction guide |
9041 |
| -as in a function declaration\iref{dcl.fct}. |
9042 |
| -The \grammarterm{simple-template-id} |
9043 |
| -shall name a class template specialization. |
9044 |
| -The \grammarterm{template-name} |
9045 |
| -shall be the same \grammarterm{identifier} |
9046 |
| -as the \grammarterm{template-name} |
9047 |
| -of the \grammarterm{simple-template-id}. |
9048 |
| -A \grammarterm{deduction-guide} |
9049 |
| -shall be declared |
9050 |
| -in the same scope |
9051 |
| -as the corresponding class template |
9052 |
| -and, for a member class template, with the same access. |
9053 |
| -Two deduction guide declarations |
9054 |
| -in the same translation unit |
9055 |
| -for the same class template |
9056 |
| -shall not have equivalent \grammarterm{parameter-declaration-clause}{s}. |
9057 |
| - |
9058 | 9058 | \indextext{template|)}
|
0 commit comments