3

If you pass a lambda function by copy in c++ what actually gets copied?

Is it just a pointer to the lambda?

Or does the whole capture list get copied as well?

Lord Nikon
  • 172
  • 8
  • 2
    lambdas are essentially just syntax sugar for creating anonymous structs with an overloaded `operator()` - so think about how passing a struct by value behaves – UnholySheep Sep 27 '21 at 20:46

1 Answers1

5

Lambda functions are usually realized as compiler generated functor classes.

Or does the whole capture list get copied as well?

The captures go to the class internal data members, and those will be copied.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190