In 14.8.2.4p10 of the C++11 draft, there is written
If for each type being considered a given template is at least as specialized for all types and more s
This answer is based on an incorrect parsing of the Standard paragraph's abstract syntax tree. The grouping of conditions assumed in the "Back to the Standard" section turned out not to be the intended one. The intended grouping is the one Johannes Schaub has shown in his answer.
Why is there then that mentioned fallback for when none of the Us are at least as specialized than the corresponding Ts?
I agree with you that the second part (actually, the whole second condition) is redundant.
Some vocabulary of reference:
Let's have some fun with logics and introduce 3 fundamental relations between two templates for a pair of corresponding parameters:
Ti and Ui respectively, one template matches the other but not vice versa. I will indicate this as Ti < Ui;Ti and Ui respectively, one template matches the other and vice versa. I will indicate this as Ti == Ui;Ti and Ui respectively, none of the templates matches the other for the particular parameter. I will indicate this as T1 ~ U1.For instance, in the code snippet below:
template struct A { };
template struct B { };
template void foo(A, X, A) { } // 1
template void foo(X, X, B) { } // 2
For the first parameter, (1) is more specialized than (<) (2); for the second parameter, (1) is equally specialized as (or "as specialized as", ==) (2); for the third parameter, (1) is specialization-incomparable to (~) (2).
And let' now define a derived relation:
Ti and Ui when (Ti < Ui) or (Ti == Ui), i.e. when either (1) is more specialized than (2) or (1) is as specialized as (2). In the above example, therefore, T1 <= U1, T2 <= U2, and U2 <= T2.Back to the Standard:
With the help of a couple of parentheses, the quote above becomes (A && (B1 || B2)):
[...] for each type being considered:
( a given template is at least as specialized for all types and more specialized for some set of types )
AND( the other template is not more specialized for any types
ORis not at least as specialized for any types )
Given two templates to be ordered with respect to the corresponding sequences of parameter types T1, ..., Tn and U1, ..., Un, the condition (A):
[...] a given template is at least as specialized for all types and more specialized for some set of types [...]
Means that for each i = 1..n, Ti <= Ui, and for some js in 1..n, it applies the stricter condition that Tj < Uj. Dropping the index i, this means that for each parameter:
(T < U) || (T == U) // (A)
This condition is put in logical conjunction ("and") with another condition (B), which is in turn the logical disjunction ("or") of two sub-conditions, (B1) and (B2). Let's start examining sub-condition (B1):
[...] the other template is not more specialized for any types [...]
This means that for any i, it is never the case that Ui < Ti, which means that either:
Ti is more specialized than Ui (Ti < Ui); orTi and Ui are equally specialized (Ui == Ti); orTi and Ui are specialization-incomparable (Ui ~ Ti):More formally:
!(U < T) <==> (T < U) || (T == U) || (T ~ U) // (B1)
Now let's see the second sub-condition (B2), which is put in logical disjunction with (B1):
[...] is not at least as specialized for any types [...]
This is the negation of U <= T, which means:
!(U <= T) <==> !((U == T) || (U < T)) ==> !(U == T) && !(U < T)
So in other words, T and U are not equally-specialized, nor U is more specialized than T. Therefore, the only possibilities left are that:
(T < U) || (T ~ U) // (B2)
Now it is evident that (B2) implies (B1), because (B2) is more restrictive. Therefore, their disjunct (B) will be coincident with (B1), and (B2) is redundant:
(T < U) || (T ~ U) || (T == U) // (B)
But what is also evident here is that (A) is stricter than (B), so the conjunction of (A) and (B) is equivalent to (A).
Conclusion:
The whole condition (B) is redundant.