c++ - std::result_of on std::bind 不能在 clang++ 3.4 上编译

标签 c++ c++11 bind clang++ result-of

以下代码使用 g++-4.8 编译,但在使用 clang 3.4 时不编译。

#include <type_traits>
#include <functional>

struct A {
    template <typename Continuation>
    bool operator()(
            //const  Continuation & continuation
            Continuation continuation
        ) const {
        return true;
    }
};

bool  f(A)  {
    return true;
}

auto g(A a) ->
typename  std::result_of<A(
    decltype(std::bind(f, a)))>::type
{
    auto continuation = std::bind(f, a);

    return a(continuation);
}

int main(int argc, char ** argv) {
    A a;
    g(a);
}

g++-4.8 -std=c++0x test.cpp # OK

clang++ -std=c++0x 测试.cpp

test.cpp:22:38: error: no type named 'type' in 'std::result_of<A (std::_Bind<bool (*(A))(A)>)>'
    decltype(std::bind(f, a)))>::type
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
1 error generated.

当您取消注释注释行并注释以下行时,代码会在 clang ang g++ 上编译。

最佳答案

result_of 在 decltype 之前,你应该像这样简化语法:

auto g(A a) -> decltype( std::declval<A>()( std::bind(f, a) ) )

关于c++ - std::result_of on std::bind 不能在 clang++ 3.4 上编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22612466/

相关文章:

c++ - 将 ## 预处理器运算符与另一个宏输出一起使用

c++ - 数组在返回时丢失值(库存/菜单程序)C++

c++ - 构造函数的参数命名

c++ - 在模板参数的方法中添加类型转换时出现 clang 错误

c++ - 为什么这个程序有这种行为(push_back)?

ubuntu - 启动 docker daemon 监听特定端口的正确方法

c++ - 在不使用交换的情况下分配最大缓冲区

c++ - 通过引用返回静态 vector 很慢

bind - 如何在 ionic 4 中绑定(bind) ionic 按钮的背景颜色

c++ - 将 char* 绑定(bind)到字符串