Several times, in code review, I'm told to add contexpr to some named lambda closure declaration, i.e. I'm told to change this
auto lam = [capture list](args){body}
to this:
constexpr auto lam = [capture list](args){body}
Therefore, I'd like to understand what the conditions are that allow a lambda closure to be declared as constexpr, so I can make this change autonomously.
Here I read that
A constexpr variable must satisfy the following requirements:
- its type must be a LiteralType.
- it must be immediately initialized
- the full-expression of its initialization, including all implicit conversions, constructors calls, etc, must be a constant expression
- [a C++20-specific condtion]
Where I see that the second condition is verified, but I'd like some help understanding the first and especially the third condition.
Concerning the first condition, at the LiteralType page I understand that it is enough, for a variable to be a LiteralType, to be a possibly cv-qualified class type that has a destructor (how could it not have one?) and is a closure type (which is the case for the lam above), and all non-static data members and base classes are of non-volatile literal types (I'm not sure about this last part in relation to lambdas).
The bottom line is that I'd like to understand how I can understand, by inspection, if I can make a lambda constexpr.