Matching of class template partial specializations

前端 未结 2 616
天命终不由人
天命终不由人 2021-01-04 04:12

N4527 14.5.5.1[temp.class.spec.match]

2 A partial specialization matches a given actual template argument list if the template arguments of the partia

2条回答
  •  失恋的感觉
    2021-01-04 04:53

    The differences between rule two and rule four is the second and third template parameter. In example three:

    A a3; // uses #4, T is char

    It uses rule4 because the third parameter clearly specializes to a const int 5, and the second parameter is specialized to accept a pointer type; its a unique specialization of class A.

    I look at each specialization as a specific species of the class, and each specie has a unique signature (similar to overloading functions). The compiler is going to choose the specialization that matches the signature being used.

    Rule three only makes sense without rule five, so after removing rule five, the intent of rule three would be to specialize any typenames of class A that: a) do not use a const int 5 for the third parameter b) do not use a pointer or as the second parameter c) do not use a `int` in the second parameter.

    Since non of your examples use the unique signature of rule3, non of them use rule3 (given we remove the ambiguous rule5).

    This could be better to understand if you only look at the template<...> scheme of the specialization, and not the signature <> of the specialization. The compiler is looking at the template scheme before looking at the specialization. Also, all other specializations of class A define the rules for any new specialization. To understand the intentions of a specialization, you have to understand the intentions of all the other specializations, and intention of a specialization is not defined by the standard, its defined by whoever implemented the specialization; ie. implementation details of the specialization truly define the intent.

提交回复
热议问题