VC9のtr1の実装具合ってどんなもんだろ。
#include <iostream> #include <functional> using namespace std; int count1(int n) { return ++n; } int count2(int &n) { return ++n; } int count3(int *n) { return ++(*n); } int main() { int n1 = 0, n2 = 0, n3 = 0; tr1::function<int (void)> f1 = tr1::bind(count1, n1); tr1::function<int (void)> f2 = tr1::bind(count2, n2); tr1::function<int (void)> f3 = tr1::bind(count3, &n3); cout << "f1: " << f1() << endl; cout << "f1: " << f1() << endl; cout << "f1: " << f1() << endl; cout << "f2: " << f2() << endl; cout << "f2: " << f2() << endl; cout << "f2: " << f2() << endl; cout << "f3: " << f3() << endl; cout << "f3: " << f3() << endl; cout << "f3: " << f3() << endl; }
bindはboostの鬼門という話があったけど、tr1::bindはどうなんだろう?ばんばん使っていきたいけど。
f1: 1
f1: 1
f1: 1
f2: 1
f2: 2
f2: 3
f3: 1
f3: 2
f3: 3