问题描述
我有一些可在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 (将#修改为@)