QQ交谈 +852 2655 6100 enquiry@clustertech.com

Anonymous functor in C++11


The new C++11 standard supports programmers to write anonymous functor in a compact and clear way. The following article illustrates it: http://drdobbs.com/cpp/232500059?cid=DDJ_nl_cpp_2012-02-09_h&elq=97163375fe6044ee9d27b32e71052b60

To use an anonymous functor in a function template like std::count_if, use closure in the form [what external variables to capture](arguments){statements}

Another convenient construct that C++11 provides is a polymorphic wrapper for functor in the form std::function. It allows a functor to be used in non-template functions (so you need not expose your code). Read the article for details and it would a pleasure.

Another reference: http://www.cprogramming.com/c++11/c++11-lambda-closures.html

Visual C++ 2010 (even Express edition) is already supporting it.

Author: Chris

Improve your experience on our website

We notice that your current browser is out of date. In order to improve your experience on our website, we suggest that you upgrade your browser. Upgrading should only take a few minutes. If you are already using the most updated version, please turn off the Compatibility Mode of your browser.

最佳的瀏覽體驗

為獲取最佳的瀏覽體驗,我們建議您升級瀏覽器。如您已在使用最新版本的瀏覽器,請關閉瀏覽器相容模式以訪問網站。

最佳的浏览体验

为获取最佳的浏览体验,我们建议您升级浏览器。如您已在使用最新版本的浏览器,请关闭浏览器相容模式以访问网站。

<a target="_blank" href="http://www.getfirefox.com/">Mozilla Firefox</a><a target="_blank" href="http://www.google.com/chrome/">Google Chrome</a>