タグ

2015年3月14日のブックマーク (2件)

  • std::bindをやっと理解 - joynote break;

    bindが今までイマイチ理解できてなかったけど、書いてみたら一発で理解。 要は、function(関数ポインタ/関数オブジェクト/ラムダ式)の引数を束縛して新しいfunctionオブジェクトを生成してるのね。 #include <functional> #include <iostream> using namespace std; void Func(int a, int b) { cout << a*b << endl; } int main(){ // intの引数1つのfunction function<void (int)> func; // int引数2つのfunctionの片方を定数(3)で束縛して、int引数1つのfunctionに入れる func = bind(Func,placeholders::_1,3); // 動く func(4); return 0; } 出力結

    std::bindをやっと理解 - joynote break;
  • 【C++】std::bindの使い方 - Qiita

    #include <iostream> void test_function(int a, int b) { printf("a=%d, b=%d\n", a, b); } int main(int argc, const char * argv[]) { auto func1 = std::bind(test_function, std::placeholders::_1, std::placeholders::_2); func1(1, 2); // -> a=1, b=2 auto func2 = std::bind(test_function, std::placeholders::_1, 9); func2(1); // -> a=1, b=9 return 0; } std::bindは何をしてくれるかというと、 指定した関数をラップしたstd::functionを作る という

    【C++】std::bindの使い方 - Qiita