1. 程式人生 > >c++0x的新特性:lambda表示式

c++0x的新特性:lambda表示式

(本文摘自c++論壇裡自己帖子的回覆。

GCC4.5引入這個特性。有興趣的朋友可以編譯測試下面這段程式碼:

#include <algorithm>
#include <cmath>
void abssort(float *x, unsigned N) {
  std::sort(x, x+N,
            [](float a, float b) {  // 注意此處的方括弧
              return std::abs(a) < std::abs(b);
            });
}
更多參考:
1)http://gcc.gnu.org/gcc-4.5/cxx0x_status.html

2)http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2927.pdf
3)http://www.ibm.com/developerworks/cn/aix/library/au-gcc/注意:需要新增編譯器選項:-std=c++0x 或 -std=gnu++0xQt專案可使用:QMAKE_CXXFLAGS += -std=c++0x

【編輯】VC10對c++0x的支援: