C ++ 1y / C ++ 14:可变模板专业化? [英] C++1y/C++14: Variable Template Specialization?

查看:117
本文介绍了C ++ 1y / C ++ 14:可变模板专业化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据C ++ 1y / C ++ 14 N3690,变量模板特殊化的类型是否必须与主模板的类型相同?

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<int x>
char y = f(x);

template<>
double y<42> = g();

如果是,是否可能以某种方式离开主要未定义?

And if so, is it possible to leave the primary undefined somehow?

template<int x>
???? y = ???; // undefined

template<>
double y<42> = g();

草稿包含在哪里?

类模板的等效功能是:

template<int x>
struct S
{
    static char y;
};

template<>
struct S<42>
{
    static double y;
};

template<int x>
struct S; // undefined

template<>
struct S<42>
{
    static double y;
};


推荐答案

必须与主模板的类型相同?

否,变量模板的显式(或部分)特殊化可以指定类型不同从隐式实例化隐含的类型。当实现Clang的功能时,我们发现规范没有规则要求类型匹配在这种情况下,我们把问题提交到C ++核心工作组,其中确认这是遗漏是有意的。

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.

是否可能以某种方式离开主要未定义?

在草稿中包含了哪些内容?

这两个都是通过遗漏来覆盖的 - 没有规则要求类型匹配,并且没有语法声明变量没有类型的模板。所以我不能指出你在标准的任何特定部分,并说这里的规则是不是。

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".

如果你有权访问C ++标准委员会反射器,请参阅从core-23901开始的线程的讨论。

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

这篇关于C ++ 1y / C ++ 14:可变模板专业化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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