C++ Lambda Idioms - Timur Doumler - CppCon 2022

C++20 introduces new idioms for using lambdas, including explicit variable templates, capture parameter packs, and variadic init captures, enabling meta-programming and generating new types at compile-time and runtime.

Key takeaways
  • Lambdas without captures are not good because they’re evaluated every time they’re called.
  • In C++20, you can make a lambda an explicit variable template.
  • Lambdas can capture parameter packs.
  • You can use variadic init capture to reimplement tuple types.
  • You can use lambda expressions to generate new types at compile-time.
  • Lambdas can be inherited from.
  • In C++20, you can default template parameters to inhibit instantiation.
  • Lambdas can capture variables by value or reference.
  • You can use lambdas to implement meta-programming.
  • C++20 introduces class template argument deduction (CTAD) for aggregates.
  • Lambdas can be used as template parameters.
  • You can use lambda expressions to create closure types.
  • In C++20, you can deduce the type of a lambda when it’s converted to a function pointer.
  • Lambdas can be used to implement higher-order functions.
  • You can use lambdas as template parameters for classes.
  • Lambdas can be used to generate new types at runtime.