A Kaleidoscope of Lambdas
Dawid Zalewski
Lambda expressions have settled for good in the contemporary C++ toolbox. They can be found just about everywhere, from transforming data with algorithms or ranges
, through launching async tasks, to nifty metaprogramming tricks with concepts. No wonder, as they are easy to write, come with all the modern features included and allow for very expressive code.
Chances are that you also belong to the camp of daily lambda users. But can you really say that you know lambdas well, or that you get the most out of them? If this question gives you pause, then this talk is just for you. And for anyone else who wants to learn more about lambdas and (re-)discover their potential.
We'll start by reviewing the lambda syntax and discussing how it relates to closure objects. Then, we'll turn to the features of lambdas and their evolution up to the upcoming C++26 additions. While doing so, we'll identify the opportunities for using lambdas to simplify existing code and getting rid of those pesky std::bind
s and std::mem_fn
s. Finally, we'll talk about lambda-specific idioms, such as immediately invoked function expressions and their applications, or functional programming techniques with lambdas. Hopefully, after going through a range of common, unusual, and sometimes unexpected lambda patterns and applications you'll be better equipped to put them to use in your day-to-day practice.
Dawid Zalewski
I'm a computer engineer and passionate teacher with over 25 years of programming experience. I have co-evolved with various languages including Basic, Turbo Pascal and 8051 assembly to finally settle in the land of C++ (with occasional visits to Python, C# and a few others). I teach at a University of Applied Sciences in the Netherlands, where I try to convert new generations of programmers to the use of modern C++. My professional interests focus on the design and evolution of programming languages and paradigms. In my spare time you can find me reading, climbing, hiking, cycling or writing code.