我有这个代码:
#include <iostream>
#include <functional>
struct A
{
    int operator()(int i) const {
        std::cout << "F: " << i << std::endl;
        return i + 1;
    }
};
int main()
{
    A a;
    std::tr1::function<int(int)> f = std::tr1::ref(a);
    std::cout << f(6) << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
目的是通过reference_wrapper传递functor对象,以避免无用的复制costructor调用.我期待以下输出:
F: 6
7
Run Code Online (Sandbox Code Playgroud)
它适用于GCC> = 4.4.0,Visual Studio 2008,并通过用boost替换std :: tr1命名空间来提升.它仅适用于新的Visual Studio 2010 Express Beta 2和Release Candidate.
这个新的C++功能在vs2010中有漏洞吗?或者代码中有一些错误或误用?