0

When defining a function that takes a function parameter, should I receive a lambda/std::function by copy, reference or const reference?

Or all three?

leewz
  • 3,201
  • 1
  • 18
  • 38

1 Answers1

0

I'd go with const ref. Const because the function shouldn't be changed and ref because then the function taking the parameter doesn't have to check for null.

But don't take my word for it, it will depend case by case. Here is a duplicate post that provides other perspectives:

Should I pass an std::function by const-reference?

Community
  • 1
  • 1
bstar55
  • 3,542
  • 3
  • 20
  • 24