c++ - gcc 6.1 std::result_of 编译错误

标签 c++ c++11 gcc result-of gcc6

考虑一个小型独立用例,其中我想确定一个类型是完整的还是不完整的使用

#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/

相关文章:

c++ - 为什么这个 while 循环不退出?

c++ - 安全的跨平台协程

c++ - 包含 std::queue 的类的值初始化

linux - 需要共享 (.so) 库之间的循环依赖

c++ - 使用按位运算符的 PE 文件格式指针

c++ - 将 Eigen 类型与 STL 容器和 std::vector 一起使用

c++ - 为什么要防止 Name-mangling C 文件

c++ - 使用 lambda 作为模板参数时,这个编译器错误是什么?

c++ - 为什么 clang 找不到在调用站点之前声明的函数?

c - 链接到 .so 文件中的旧符号版本