C++0xのラムダのインライン化

インライン化されるのか調べた。
されるっぽい(g++ 4.6.3調べ)。すばらしい。
まあ関数オブジェクト作ってるだけらしいので当たり前かもしれないけど。

int func(int x){
  const auto inc = [](int x){ return x + 1; };
  return inc(x);
}

これが

_Z4funci:
.LFB0:
        .cfi_startproc
        movl    4(%esp), %eax
        addl    $1, %eax
        ret
        .cfi_endproc

こんな感じになる。

当然以下のような少し複雑なケースでも大丈夫。

struct apply{
  template<typename F>
  inline int operator () (F f) const { return f(0); }
};

int func(int x){
  return apply()([](int x){ return x + 1; });
}

こうなる

_Z4funci:
.LFB1276:
        .cfi_startproc
        movl    $1, %eax
        ret
        .cfi_endproc