Highlighting template arguments during partial ordering when parameters are a function parameter package

N4527 14.8.2.4 [temp.deduct.partial]

3 The types used to determine the order depend on the context in which partial ordering is performed:

(3.1) - In the context of a function call, those types of functions are used for which the function call has arguments.

(3.2) - In the context of invoking a transform function, the return types of the transform function patterns are used.

(3.3) - In other contexts (14.5.6.2), the function type of function templates is used.

4 Each type indicated above from the parameter template and the corresponding type from the template argument are used as Pand types A.

8 If it Awas converted from a function parameter package, and is Pnot a parameter package, type inference is not performed. Otherwise, using the resulting types Pand A, the deduction is then performed as described in 14.8.2.5. If it Pis a function parameter package, the type of Aeach remaining parameter of the argument template parameter is compared to the type of Pthe declarator identifier of the function parameter package. Each comparison displays the template arguments for subsequent positions in the parameter template packages extended by the parameter package function. If the output for a successful type is specified, the type from the argument template is considered to be at least as specialized as the type from the parameter template. [Example:

template<class... Args>           void f(Args... args);        // #1
template<class T1, class... Args> void f(T1 a1, Args... args); // #2
template<class T1, class T2>      void f(T1 a1, T2 a2);        // #3

f();        // calls #1
f(1, 2, 3); // calls #2
f(1, 2);    // calls #3; non-variadic template #3 is more
            // specialized than the variadic templates #1 and #2

Why f(1, 2, 3);is calling # 2?

I need more details, including:

1 ?

2 ?
. # 1 void (U), void (U...) ? (U )

14.5.6.2 [temp.func.order]/p3

, , - ( (14.5.3)) , .

3 P A ? ,

template <class T> void f(T);
int a = 1;
f(a);//P = T, A = int
+4
1

f(1, 2, 3); # 2?

( , !), . -, . # 3 , # 1 # 2 :

template<class... Args>
void f(Args... args);        // #1, with Args = {int, int, int}
template<class T1, class... Args> 
void f(T1 a1, Args... args); // #2, with T1 = int, Args = {int, int}

int , . , :

, F1 , F2, i ICS i (F1) , ICS i (F2),
- [...]
- F1 F2 - , F1 - F2 , 14.5.6.2.

:

1: [temp.func.order]:

, , - ( (14.5.3)) , .

, :

void f(Pack1... args);         // #1
void f(U2 a1, Pack2... args);  // #2

2: , [temp.deduct.partial]. , , , , .

# 2 # 1. (T1, Args...) (Pack1...). P = T1, A = Pack1.... :

A , P , .

# 2 # 1 , Args... , , , T1, Args....

# 1 # 2. (Args...) (U2, Pack2...). , T1, Args... , Args....

# 2 , # 1 # 1, , , # 2, , # 2 :

F , G, , , F , G. F G, F G G , , , F.

, # 2.

+3

Source: https://habr.com/ru/post/1605717/


All Articles