微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Visual C ++错误,用于在尾随返回类型?中给模板化的结构变量加上别名

如何解决Visual C ++错误,用于在尾随返回类型?中给模板化的结构变量加上别名

我有一些可在Clang上编译的代码,但被Visual C ++拒绝。我设法将其分解为以下示例:

template <typename T>
static constexpr bool BoolValue = std::is_same_v<T,int>;

template <typename X>
struct Struct final
{
    template <typename T,typename U>
    static constexpr bool BoolValue = std::is_same_v<T,U>;

    template <typename Y>
    auto method() -> std::enable_if_t<BoolValue<X,Y>>;
};

template <typename X>
template <typename Y>
auto Struct<X>::method() -> std::enable_if_t<BoolValue<X,Y>> {}

似乎最后一行中的尾随返回类型应引用Struct::BoolValue ::BoolValue。它可在Clang上运行,但被Visual C ++ 2019(最新版本)拒绝:

error C2977: 'BoolValue': too many template arguments
message : see declaration of 'BoolValue'
error C2993: 'unkNown-type': is not a valid type for non-type template parameter '_Test'
error C2976: 'std::enable_if_t': too few template arguments
message : see declaration of 'std::enable_if_t'
error C2244: 'Struct<X>::method': unable to match function deFinition to an existing declaration
message : see declaration of 'Struct<X>::method'
message : deFinition
message : 'unkNown-type Struct<X>::method(void)'
message : existing declarations
message : 'enable_if<Struct<X>::BoolValue<X,Y>,void>::type Struct<X>::method(void)'

我怀疑这是一个编译器错误,但我想先检查一下:此代码有效吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。