Files
2025-10-25 03:02:53 +03:00

58 lines
3.8 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[temp.deduct.guide]
# 13 Templates [[temp]](./#temp)
## 13.7 Template declarations [[temp.decls]](temp.decls#temp.deduct.guide)
### 13.7.2 Class templates [[temp.class]](temp.class#temp.deduct.guide)
#### 13.7.2.3 Deduction guides [temp.deduct.guide]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2823)
Deduction guides are used
when a [*template-name*](temp.names#nt:template-name "13.3Names of template specializations[temp.names]") or [*splice-type-specifier*](dcl.type.splice#nt:splice-type-specifier "9.2.9.9Type splicing[dcl.type.splice]") appears as a type specifier
for a deduced class type ([[dcl.type.class.deduct]](dcl.type.class.deduct "9.2.9.8Deduced class template specialization types"))[.](#1.sentence-1)
Deduction guides are not found by name lookup[.](#1.sentence-2)
Instead, when performing class template argument deduction ([[over.match.class.deduct]](over.match.class.deduct "12.2.2.9Class template argument deduction")),
all reachable deduction guides declared for the class template are considered[.](#1.sentence-3)
[deduction-guide:](#nt:deduction-guide "13.7.2.3Deduction guides[temp.deduct.guide]")
[*explicit-specifier*](dcl.fct.spec#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]")opt [*template-name*](temp.names#nt:template-name "13.3Names of template specializations[temp.names]") ( [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6Functions[dcl.fct]") ) -> [*simple-template-id*](temp.names#nt:simple-template-id "13.3Names of template specializations[temp.names]") [*requires-clause*](temp.pre#nt:requires-clause "13.1Preamble[temp.pre]")opt ;
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2837)
[*Example [1](#example-1)*: template<class T, class D = int>struct S { T data;};template<class U> S(U) -> S<typename U::type>;
struct A {using type = short; operator type();};
S x{A()}; // x is of type S<short, int> — *end example*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L2855)
The same restrictions apply
to the [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6Functions[dcl.fct]") of a deduction guide
as in a function declaration ([[dcl.fct]](dcl.fct "9.3.4.6Functions")),
except that a generic parameter type placeholder ([[dcl.spec.auto]](dcl.spec.auto "9.2.9.7Placeholder type specifiers"))
shall not appear in the [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6Functions[dcl.fct]") of
a deduction guide[.](#3.sentence-1)
The [*simple-template-id*](temp.names#nt:simple-template-id "13.3Names of template specializations[temp.names]") shall name a class template specialization[.](#3.sentence-2)
The [*template-name*](temp.names#nt:template-name "13.3Names of template specializations[temp.names]") shall be the same [*identifier*](lex.name#nt:identifier "5.11Identifiers[lex.name]") as the [*template-name*](temp.names#nt:template-name "13.3Names of template specializations[temp.names]") of the [*simple-template-id*](temp.names#nt:simple-template-id "13.3Names of template specializations[temp.names]")[.](#3.sentence-3)
A [*deduction-guide*](#nt:deduction-guide "13.7.2.3Deduction guides[temp.deduct.guide]") shall inhabit the scope
to which the corresponding class template belongs
and, for a member class template, have the same access[.](#3.sentence-4)
Two deduction guide declarations
for the same class template
shall not have equivalent [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6Functions[dcl.fct]")*s* if either is reachable from the other[.](#3.sentence-5)