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

3.8 KiB

[temp.deduct.guide]

13 Templates [temp]

13.7 Template declarations [temp.decls]

13.7.2 Class templates [temp.class]

13.7.2.3 Deduction guides [temp.deduct.guide]

1

#

Deduction guides are used when a template-name or splice-type-specifier appears as a type specifier for a deduced class type ([dcl.type.class.deduct]).

Deduction guides are not found by name lookup.

Instead, when performing class template argument deduction ([over.match.class.deduct]), all reachable deduction guides declared for the class template are considered.

deduction-guide:
explicit-specifieropt template-name ( parameter-declaration-clause ) -> simple-template-id requires-clauseopt ;

2

#

[Example 1: template<class T, class D = int>struct S { T data;};template S(U) -> S;

struct A {using type = short; operator type();}; S x{A()}; // x is of type S<short, int> — end example]

3

#

The same restrictions apply to the parameter-declaration-clause of a deduction guide as in a function declaration ([dcl.fct]), except that a generic parameter type placeholder ([dcl.spec.auto]) shall not appear in the parameter-declaration-clause of a deduction guide.

The simple-template-id shall name a class template specialization.

The template-name shall be the same identifier as the template-name of the simple-template-id.

A deduction-guide shall inhabit the scope to which the corresponding class template belongs and, for a member class template, have the same access.

Two deduction guide declarations for the same class template shall not have equivalent parameter-declaration-clauses if either is reachable from the other.