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>