简体   繁体   English

别名模板的部分专业化

[英]Partial Specialization of Alias Templates

Partial specializations of alias templates are not permitted: 不允许使用别名模板的部分特化:

For example, trying to be creative, yields this error in clang: 例如,尝试创造性,在clang中产生此错误:

template <typename T>
using unwrapped_future_t = T;

template <typename T>
using unwrapped_future_t<future<T>> = typename future<T>::value_type;
                        ^~~~~~~~~~~
> error: partial specialization of alias templates is not permitted

Why is this not permitted? 为什么不允许这样做?

You can find the answer in the original proposal of alias templates: 您可以在别名模板的原始提案中找到答案:

2.2 The Main Choice: Specialization vs. Everything Else 2.2主要选择:专业化与其他一切

After discussion on the reflectors and in the Evolution WG, it turns out that we have to choose between two mutually exclusive models: 在讨论了反射器和Evolution WG后,我们发现我们必须在两个相互排斥的模型之间进行选择:

  1. A typedef template is not itself an alias; typedef模板本身不是别名; only the (possibly-specialized) instantiations of the typedef template are aliases. 只有typedef模板的(可能是专用的)实例化才是别名。 This choice allows us to have specialization of typedef templates. 这个选择允许我们对typedef模板进行专门化。

  2. A typedef template is itself an alias; typedef模板本身就是一个别名; it cannot be specialized. 它不能专业化。 This choice would allow: 这个选择将允许:

    • deduction on typedef template function parameters (see 2.4) 对typedef模板函数参数的推论(见2.4)
    • a declaration expressed using typedef templates be the same as the declaration without typedef templates (see 2.5) 使用typedef模板表示的声明与不带typedef模板的声明相同(参见2.5)
    • typedef templates to match template template parameters (see 2.6) typedef模板以匹配模板模板参数(参见2.6)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM