現在(N2550)のラムダ式の operator() は const 修飾されているため
キャプチャした変数を書き換えることができない
int x; [x]() { ++x; }; // エラー
はしょってるけど、↑のラムダ式は以下と同じ
class F { int x; public: void operator()() const { ++x; } };
そこで、ラムダ式によって生成される匿名クラスの operator() から const 修飾を外し
ラムダ式に CV 修飾(const/volatile)できるようにしようという案が出ている
int x; [x]() { ++x; }; // OK [x]() const { ++x; }; // エラー
template <class F> void by_copy(F f) { f(); } template <class F> void by_const_reference(const F& f) { f(); } by_copy([](){}); // OK by_copy([]() const {}); // OK by_const_reference([](){}); // エラー by_const_reference([]() const {}); // OK
N2651 Constness of Lambda Functions