Vlad's blog

In programming veritas

Archive for August 2011

Lamda expressions in C++0x

leave a comment »

New C++0x standard introduces a lot of handy features and lamda expression is one of the most powerfull constructions out of the box. It can significantly reduce a complexity of many routine tasks. This post is brief introduction of lambda syntax and techniques that can be used in conjunction with lambda expressions.
For the sake of simplicity suppose we want to print out std::vector. STL recommends using of std::for_each algorithm that receives a functor as the final argument.

struct Print
{
	void operator()(int n) const
	{
		std::cout << n << std::endl;
	};
};

std::vector<int> a;
a.push_back(1);
a.push_back(2);
a.push_back(3);

std::for_each(a.begin(), a.end(), Print());

Read the rest of this entry »

Written by vsukhachev

August 18, 2011 at 10:15 am

Posted in Development

Tagged with ,