gpt4 book ai didi

c++ - 别名模板的部分特化

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:07:31 28 4
gpt4 key购买 nike

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

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

为什么不允许这样做?

最佳答案

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

2.2 The Main Choice: Specialization vs. Everything Else

After discussion on the reflectors and in the Evolution WG, it turns out that we have to choose between two mutually exclusive models:

  1. A typedef template is not itself an alias; only the (possibly-specialized) instantiations of the typedef template are aliases. This choice allows us to have specialization of typedef templates.

  2. A typedef template is itself an alias; it cannot be specialized. This choice would allow:

    • deduction on typedef template function parameters (see 2.4)
    • a declaration expressed using typedef templates be the same as the declaration without typedef templates (see 2.5)
    • typedef templates to match template template parameters (see 2.6)

关于c++ - 别名模板的部分特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21774471/

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