Lambda (c++)

A lambda can only be converted to a function pointer if it does not capture - SO

Possible workaround using std::function / SO

#include <functional>
#include <utility>

struct Decide
{
  using DecisionFn = std::function<bool()>;
  Decide(DecisionFn dec) : dec_ {std::move(dec)} {}
  DecisionFn dec_;
};

int
main()
{
  int x = 5;
  Decide greaterThanThree { [x](){ return x > 3; } };
}

All About Lambda Function in C++(From C++11 to C++20)

caption

Written on September 13, 2020, Last update on September 14, 2020
c++