std::ref
を使用する正しい方法は何ですか?私はVS2010で次のコードを試してみましたが、それがコンパイルされません:std :: refの使い方は?
#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;
}
エラー:
C:\プログラムファイル(x86の)は、MicrosoftのVisual Studio \ 10.0 \ VCの\に\ xxresultが含まれる(28 ):エラーC2903: '結果':シンボルはクラステンプレートでも関数テンプレートでもありません。
c:\ program files(x86)\ microsoft visual studio 10.0 \ vc \ include \ xxresult(28):エラーC2143:構文エラー: ';'がありません「<」
プラスもう少し前に...
それはでコンパイルg ++(4.6と4.8の両方)。 – kennytm
@nabulke:C++ 11でも?私はこれがうまくいくと思った。 – Asha