考虑一个小型独立用例,其中我想确定一个类型是完整的还是不完整的使用
#include <type_traits>
namespace {
struct foo {
template<class T, std::size_t = sizeof(T)>
std::false_type operator()(T&);
std::true_type operator()(...);
};
struct FooIncomplete;
}
int main() {
std::result_of<foo(FooIncomplete&)>::type();
return 0;
}
使用 gcc 4.9.3
和 --std=c++11
标志可以很好地编译。但是,对于 gcc 6.1
和 --std=c++11
,它会生成一个 compilation error。作为
main.cpp: In function 'int main()':
main.cpp:17:5: error: 'type' is not a member of 'std::result_of<{anonymous}::foo({anonymous}::FooIncomplete&)>'
std::result_of<foo(FooIncomplete&)>::type();
我在这里错过了什么?有什么可能的解决方法?
最佳答案
因为 C++14 result_of::type 不存在,如果 T 不可调用。
在你的例子中,struct FooIncomplete 没有什么可调用的。
关于c++ - gcc 6.1 std::result_of 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42549813/