为什么班级部分专业化的格式正确? [英] Why is in-class partial specialization well-formed?

查看:81
本文介绍了为什么班级部分专业化的格式正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据[temp.class.spec] 5/(强调我的意思)

According to [temp.class.spec] 5/ (emphasis mine)

可以声明或重新声明类模板的部分专业化 在任何命名空间范围中,相应的主模板可能 被定义

A class template partial specialization may be declared or redeclared in any namespace scope in which the corresponding primary template may be defined

这表明部分专业化(就像在显式专业化的情况下一样)必须出现在名称空间范围中.这实际上是通过以下段落中的示例确认的:

This would suggest that partial specialization (just like in case of explicit specialization) have to appear in the namespace scope. This is actually confirmed by the example below the paragraph:

template<class T> struct A {
     struct C {
          template<class T2> struct B { };
     };
};
// partial specialization of A<T>::C::B<T2>
template<class T> template<class T2>
     struct A<T>::C::B<T2*> { };

//...
A<short>::C::B<int*> absip; // uses partial specialization

另一方面 C ++标准核心语言有效727号问题的示例表明,班级部分专业化的结构良好:

On the other hand C++ Standard Core Language Active Issues No 727 example suggests that in-class partial specialization is well formed:

struct A {
  template<class T> struct B;
  template <class T> struct B<T*> { }; // well-formed
  template <> struct B<int*> { }; // ill-formed
};

我确定此处的核心问题文档是正确的,但是找不到适当的参考资料来确认这一点.你能帮我吗?

I'm sure core issues document is correct here, but cannot find appropriate reference to confirm that. Can you help me?

推荐答案

目的是确保其有效—参见 N4090 :

The intent is that it is valid—see N4090:

在2014年Issaquah中对DR 1755 7 和DR 727 8 进行了简要讨论之后,并基于对核心反射镜 9 的讨论 10 11 ,似乎Core收敛于成员模板及其专业化的以下规则:部分专业化和显式专业化可以是第一个 在以下位置声明:最内层的类作用域或包含 命名空间范围(认识到明确声明专业化) 不构成将成员添加到类中,因此可以完成 在大括号后面).

Following a brief discussion of DR 17557 and DR 7278 in Issaquah 2014, and based on discussion on the core-reflector91011, it seems as if Core is converging on the following rules for member templates and their specializations: Partial specializations and explicit specializations can be first declared at either innermost-enclosing-class scope or enclosing namespace scope (recognizing that explicitly declaring specializations does not constitute adding members to a class and hence can be done after the closing brace).

7 http://www.openstd.org/jtc1/sc22/wg21/docs/cwg_toc.html#727
8 http://www.openstd.org /jtc1/sc22/wg21/docs/cwg_toc.html#1755
9 http://accu.org/cgibin/wg21 /message?wg = core& msg = 24366 (24033、24290、24309、24368)
10 http://accu.org/cgibin /wg21/message?wg = core& msg = 24731 (24731、24732、24736、24738)
11 http://accu.org/cgibin/wg21 /message?wg = core& msg = 25168 (25168-25179)

7 http://www.open­std.org/jtc1/sc22/wg21/docs/cwg_toc.html#727
8 http://www.open­std.org/jtc1/sc22/wg21/docs/cwg_toc.html#1755
9 http://accu.org/cgi­bin/wg21/message?wg=core&msg=24366(24033, 24290, 24309, 24368)
10 http://accu.org/cgi­bin/wg21/message?wg=core&msg=24731(24731, 24732, 24736, 24738)
11 http://accu.org/cgi­bin/wg21/message?wg=core&msg=25168 (25168­-25179)

我提出了一个核心问题,因为我觉得当前的措词还不够清楚;您引用的段落可以解释为不允许类内部分专业化.

I filed a core issue, because I feel the current wording is not clear enough; the paragraph you quoted can be interpreted to disallow in-class partial specializations.

这篇关于为什么班级部分专业化的格式正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆