Suppose you have a scenario when you want to create a constexpr
lambda inside a method for calculating something at compile time.
struct A {
int a;
constexpr A(int a) : a(a) {}
constexpr auto operator+(const A& rhs) {
constexpr auto l = [&]() {
return A(this->a + rhs.a);
};
return l();
}
};
This code doesn't compile because compiler said that this
and rhs
are not constant expressions. Is there a way for passing this
and rhs
to a local constexpr
lambda?