When is a template more specialized than the other? 'And'/'Or' confusion with logics.

前端 未结 2 1971
無奈伤痛
無奈伤痛 2021-02-05 14:10

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

2条回答
  •  [愿得一人]
    2021-02-05 14:15

    Update: This has now been added as an official C++ Issue


    I have finally figured out how to read the paragraph in question. Below I have bulleted it

    If 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, or
    • {the other template} is not at least as specialized for any types,

    then the given template is more specialized than the other template.

    This way the following first template is also more specialized than the second template

    template void f(T*);
    template void f(T);
    

    Note that the first template's parameter is at least as specialized as the second template, but is not defined to be "more specialized" - that term only applies for the case where both parameters were references and certain conditions apply (see paragraph 9 of 14.8.2.4) . The rules are apparently not meant to follow any formal ordering laws. The second template is not at least as specialized as the first template. This means that the second bullet applies, and not the first.

提交回复
热议问题