【问题标题】:Partial Specialization of Alias Templates别名模板的部分专业化
【发布时间】:2014-02-14 08:40:23
【问题描述】:

别名模板的部分特化是不允许的:

例如,尝试有创意,会在 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

为什么不允许这样做?

【问题讨论】:

    标签: c++ templates c++11 template-specialization partial-specialization


    【解决方案1】:

    您可以在别名模板的original proposal 中找到答案:

    2.2 主要选择:专业化与其他一切

    在讨论了反射器和 Evolution WG 之后,事实证明我们必须在两个互斥模型之间进行选择:

    1. typedef 模板本身不是别名;只有 typedef 模板的(可能是专门的)实例是别名。这种选择允许我们对 typedef 模板进行专门化。

    2. typedef 模板本身就是一个别名;它不能被专门化。这种选择将允许:

      • typedef模板函数参数推导(见2.4)
      • 使用 typedef 模板表达的声明与不使用 typedef 模板的声明相同 typedef 模板(见 2.5)
      • typedef 模板匹配模板模板参数(见 2.6)

    【讨论】:

    • 下一句是“这篇论文提出了选项 1,因此有利于专业化……”为什么选择该选项的答案在哪里?
    • @Lack 我知道的不多,但我可以猜到:委员会投票,选项 2 多数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多