- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这里是一个简单的例子:
#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 实现吗? (我把它写成解决方法)。
最佳答案
我认为这是 std::result_of
实现中的错误或 std::declval<>()
.
C++11 标准第 20.9.7.6 段(表 57)指定以下内容必须适用于 result_of
:
If the expression
INVOKE(declval<Fn>(),
is well formed when treated as an unevaluated operand (Clause 5), the member typedef
declval<ArgTypes>()...)type
shall name the typedecltype(INVOKE(declval<Fn>(),
otherwise, there shall be no member type.
declval<ArgTypes>()...));
在这种情况下,INVOKE(declval<A&>(), declval<int>())
解析为调用 A
类型的左值具有 int
类型的右值(参见第 20.8.2/1 段)。
考虑 A
的调用运营商, 成员类型定义 type
应解决int
.
关于c++ - std::result_of 不适用于 visual studio 2012 中 operator() 具有右值参数的仿函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16839624/
我是一名优秀的程序员,十分优秀!