Archive

Posts Tagged ‘Lambda function’

C++11: About Lambda Functions

September 22, 2012 2 comments

One of my favourite inclusions in C++11 – the latest iteration of C++, formerly known as C++0x – is the ability to create lambda functions. Lambda functions are nothing more than unnamed, essentially anonymous functions that you can define in place of where you would usually use a function name, pointer or reference, and they come in particularly handy in combination with STL, although they are certainly not limited to that use. If you have become used to using Boost.Lambda in your applications, C++11’s lambda functions provide a more convenient syntax while also eliminating your code’s dependency on Boost.Lambda.

As with function pointers and references, lambda functions can be defined as variables, passed to and returned from other functions (including other lambda functions) and so on.

Ground Rules

Let us begin with a simple example comparing the use of C++11 and Boost.Lambda when iterating over a few numbers in an STL vector:

Read more…

Advertisements
%d bloggers like this: