C++1y/C++14: Variable Template Specialization?

后端 未结 4 2033
[愿得一人]
[愿得一人] 2020-12-13 18:02

According to C++1y/C++14 N3690, does the type of a variable template specialization have to be the same as the type of the primary template?

template

        
4条回答
  •  北荒
    北荒 (楼主)
    2020-12-13 18:55

    Does the type of a variable template specialization have to be the same as the type of the primary template?

    No, an explicit (or partial) specialization of a variable template can specify a type different from the type that would be implied by an implicit instantiation. When implementing the feature for Clang, we discovered that the specification had no rule requiring the type to match in this case, and we brought the issue to the C++ core working group, where it was confirmed that this omission was intentional.

    Is it possible to leave the primary undefined somehow?

    It is not possible to declare the primary variable template without specifying a type -- there is no syntax that would allow such a thing.

    Where is this covered in the draft?

    Both of these are covered by omission -- there is no rule requiring the types to match, and there is no syntax for declaring a variable template without a type. So I can't point you at any particular part of the standard and say "here's where the rule isn't".

    If you have access to the C++ standard committee's reflectors, see the thread starting with core-23901 for the discussion of this.

提交回复
热议问题