gpt4 book ai didi

c++ - 限制声明可以在显式特化中的规范规则在哪里?

转载 作者:行者123 更新时间:2023-12-04 17:15:21 26 4
gpt4 key购买 nike

关于显式特化的语法

explicit-specialization:

template < > declaration

声明:

  • block-declaration
  • nodeclspec-function-declaration
  • ...
  • explicit-instantiation
  • ...

声明 可以是任何对其语法有效的声明。考虑这个例子

template<class T>
struct A{
template<class Y>
struct B{};
};

template<>
template struct A<int>::B<int>; //declaration: explicit-instantiation

GCC 和 Clang 都无法识别 syntax .限制声明不能显式实例化的规则在哪里?

最佳答案

正如您提到的,显式特化的语法需要在 template<> 之后进行声明 .然而,仅仅因为一些语法满足语法产生规则,它不一定是有效代码。

在显式特化的情况下,可以使用此语法显式特化的实体列在 temp.expl.spec#1

An explicit specialization of any of the following:

(1.1) function template

(1.2) class template

...

可以通过template<>引入的声明来声明...

语法 template struct A<int>::B<int>;是显式实例化,此处未列出,因为它不是可以显式特化的实体。

关于c++ - 限制声明可以在显式特化中的规范规则在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68796960/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com