C++ lambda

Poby’s Home
Feb 22, 2021

--

a throwaway function

Lambda data type

[capture list](parameter list) -> return type { body };

capture list

  • which outside variables are available in the body
  • if they should be captured by value or reference
  • C++11 has a capture list by value or by reference
  • C++14 added capture by move
  • C++17 added the ability to capture *this by value
  • scoping, watch dangling references
  • if you are using capture by value, it is captured by const value
  • to allow the captured value to be changed, add mutable before body

Capture example 1

Capture example 2

--

--