Re:The Evolutions of Lambdas in C++14, C++17 and C++20
by cyber_kinetist on Monday December 13, 2021 @09:54AM
(#29540082)
If you're not capturing variables that allocate memory (like std::vector or std::string), there will be no allocations. And if you're that sensitive about hidden allocations, chances are that you're going to avoid most of these STL types in the first place (no allocating constructors or RAII), so you won't probably need to worry about this. Even the people using C-like C++ ("Orthodox" C++) seem to use lambdas liberally when it make sense.
(Or maybe you're talking about putting a lambda into an std::function, which is a totally different thing and will probably incur heap allocation?)
(Or maybe you're talking about putting a lambda into an std::function, which is a totally different thing and will probably incur heap allocation?)