这里简单的例子:
#include <type_traits>
int foo() {
return 2;
}
struct A {
int operator()(int&& x) {
return x*2;
}
};
int main(int, char**) {
std::result_of<A&(int)>::type x = 42;
return 0;
}
当我尝试在 VisualStudio 2012 中编译它时出现错误:
error C2664: 'int A::operator ()(int &&)' : cannot convert parameter 1 from 'int' to 'int &&'
You cannot bind an lvalue to an rvalue reference
我在 mingw-g++ 中编译了相同的代码,一切正常。除了编写自己的 result_of 实现之外,我还能做些什么吗?(我把它写成解决方法)。