What does return [value] is supposed to do.
constexpr int Increment(int value)
{
return [value] { return value + 1; }();
};
What does return [value] is supposed to do.
constexpr int Increment(int value)
{
return [value] { return value + 1; }();
};
This code demonstrates a feature of c++ that a lamda can be made constexpr. Which is not possible before c++17. there is lamda expression called while return
#include <iostream>
constexpr int Increment(int value) {
return [value] { return value + 1; }();
};
int main()
{
Increment(10);
static_assert(11 == Increment(10), "Increment does not work correctly");
return 0;
}