jeudi 3 septembre 2015

Deducing template arguments during partial ordering when parameters are function parameter pack

N4527 14.8.2.4 [temp.deduct.partial]

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

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

(3.2) — In the context of a call to a conversion function, the return types of the conversion function templates are used.

(3.3) — In other contexts (14.5.6.2) the function template’s function type is used.

4 Each type nominated above from the parameter template and the corresponding type from the argument template are used as the types of P and A.

8 If A was transformed from a function parameter pack and P is not a parameter pack, type deduction fails. Otherwise, using the resulting types P and A, the deduction is then done as described in 14.8.2.5. If P is a function parameter pack, the type A of each remaining parameter type of the argument template is compared with the type P of the declarator-id of the function parameter pack. Each comparison deduces template arguments for subsequent positions in the template parameter packs expanded by the function parameter pack. If deduction succeeds for a given type, 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); calls #2?

I need more details including:

1 Which context is it?

2 What are the transformed froms?
e.g. the transformed from of #1 is void (U) , void (U...) or other form?(U means an unique type)

14.5.6.2 [temp.func.order]/p3

To produce the transformed template, for each type, non-type, or template template parameter (including template parameter packs (14.5.3) thereof) synthesize a unique type, value, or class template respectively and substitute it for each occurrence of that parameter in the function type of the template.

3 What are the types of P and A used in deduction? e.g

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

Aucun commentaire:

Enregistrer un commentaire