C++では関数オブジェクトのほうが関数より速い。呼び出しの時間に差がある様子。 数回呼ぶだけなら誤差だが呼ぶ回数が増えるとその速度は有利。 ソート std::sortの比較関数に関数や関数オブジェクトを与える。 関数 bool cmp(int x, int y) { return x < y; } 関数オブジェクト struct cmp_c { bool operator()(int x, int y) { return x < y; } } cmp; ファンクタとかファンクショノイドとか呼ばれる。cmpは上の関数のcmpと同じように呼ぶことができる。 ラムダ式 auto cmp = [](int x, int y) -> bool { return x < y; }; C++11の記法。関数オブジェクトが作られる。 cmpの型はfunction< bool(int,int) >かと思われ
![C++の関数オブジェクトが関数よりどれだけ速いか - でも今日はSRMあるから](https://cdn-ak-scissors.b.st-hatena.com/image/square/28802878cf3f884550a55245ef54eecc43924293/height=288;version=1;width=512/http%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fn%2Fnatsugiri%2F20150317%2F20150317072840.png)