D1167R0
Mike Spertus, Symantec
mike_spertus@symantec.com
2018-10-08
Audience: Evolution Working Group
C++17 | Proposed | ||
---|---|---|---|
|
|
||
|
|
| |||
C++17 | Proposed | ||
---|---|---|---|
|
|
C++17 | Proposed | ||
---|---|---|---|
|
|
| |||
C++17 | Proposed | ||
---|---|---|---|
|
|
In such a case, we deduce the pair<int, T> by following the same process as used for alias templates in P1021R1, thereby deducing T. For example, f({{}, 2L}) will deduce f<long>, which takes a pair<int, long> as an argument. For the technical details, see P1021R1, which has a step-by-step walkthrough for deducing pair<int, T>.
template
<
typename
T>
void
f(pair<
int
, T>);
While Class Template Argument Deduction uses both implicit and explicit deduction guides, Function Template Argument Deduction in effect uses only implicit guides (ordinary Function Template Argument deduction). Given that it often proves helpful to override the implicit deduction behavior of class templates, would the same be true for function templates? The answer is a resounding “yes”.
std::reference_wrapper is commonly used to effect pass-by-reference to function templates with generic parameter types, but this is rarely used outside the standard library we believe due to the ugliness of forcing the correct deduction. If, as we propose, deduction guides could be provided for implicit guides, unwrapping would be straightforward, both inside the standard library and in user code:
C++17 | Proposed | ||
---|---|---|---|
|
|
As another example, for function templates that accept am “in” argument, it is common to want to accept small argument types, such as int, by value and large or uncopyable types by const &. Unfortunately, this is rarely done as the implicitly-generated rules for Function Template Argument Deduction do not readily provide the desired behavior. With deduction guides, this again naturally simplifies to a form that no longer requires examining the body of f to understand how arguments are passed:
C++17 | Proposed | ||
---|---|---|---|
|
|