如何使用std :: ref?

Ash*_*sha 10 c++ stl c++11

什么是正确的使用方法std::ref?我尝试在VS2010中使用代码并且它不能编译:

#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;
struct IsEven
{
    bool operator()(int n) 
    {
        if(n % 2 == 0)
        {
            evens.push_back(n);
            return false;
        }

        return true;
    }

    vector<int> evens;
};
int main(int argc, char **argv)
{
    vector<int> v;
    for(int i = 0; i < 10; ++i)
    {
        v.push_back(i);
    }

    IsEven f;
    vector<int>::iterator newEnd = remove_if(v.begin(), v.end(), std::ref(f));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误:

c:\ program files(x86)\ microsoft visual studio 10.0\vc\include\xxresult(28):error C2903:'result':symbol既不是类模板也不是函数模板

c:\ program files(x86)\ microsoft visual studio 10.0\vc\include\xxresult(28):错误C2143:语法错误:缺少';' 在'<'之前

还有一些......

Che*_*Alf 9

Visual C++ 10.0实现中存在一个错误或一组错误std::ref.

据报道,已修复Visual C++ 11; 看到我之前的问题.

微软的STL如此回答:"我们已经修复了它,修复程序将在VC11 RTM中提供.(但是,修复程序没有进入VC11测试版.)"