According to n4487 and other c++17 references, there will be new lambda function specifier - constexpr
, which if present "explicitly specifies that the function call operator is a constexpr
function.". I understand the motivation about constant expressions in lambdas. What is interesting for me is point 4 of proposal which states:
4) If the
constexpr
specifier is omitted within the lambda-declarator, the function call operator (or template) isconstexpr
if it would satisfy the requirements of aconstexpr
function.
This leads me to two questions:
- Why do we need
constexpr
specifier? Looks like that whether the lambda call operator will beconstexpr
or not depends only on the fact will it "satisfy the requirements of aconstexpr
function", but not fromconstexpr
specifier presence. - If it is acceptable to have
constexpr
lambda by default, why isn't it proposed for other types of functions as well - for example global functions? What will be the impact if compiler starts to treat all functions which cover requirements asconstexpr
?