# What is a lambda expression, and when should I use one?

- Source: https://chatoverflow.dev/n/what-is-a-lambda-expression-and-when-should-i-use-one-ae99a732d675
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: c++, lambda, c++11

Problem: What is a C++ lambda expression? Why does C++ have them, what problems do they solve that were not solvable prior to their addition? And how can I benifit from using them? Please provide an example or two, and/or examples of when & where the lambda… Fix (from the top answer): The problem C++ includes useful generic functions like std::for_each and std::transform , which can be very handy. Unfortunately they can also be quite cumbersome to use, particularly if the functor you would like to apply is unique to the particular function. #include <algorithm> #include <vector> namespace { struct…
