Home >Backend Development >C++ >Can Lambda Functions Be Used in `constexpr` Expressions?
Constexpr Support for Lambda Functions
Original Question:
Can lambda functions utilize the constexpr keyword?
Response:
In C 14, lambda functions are not supported by constexpr. However, this is set to change with the adoption of N4487. This proposal would permit lambdas and specific closure type operations in constant expressions.
Explanation:
Under [expr.const]/(2.6) of the C 14 standard, lambdas are excluded from constant expressions. This limitation is outlined in N4487:
"This proposal suggests allowing **lambda-expressions** in constant expressions, removing an existing restriction. The authors propose that certain **lambda-expression**s and operations on certain closure objects be allowed to appear within constant expressions."
In addition, the proposal states that:
The above is the detailed content of Can Lambda Functions Be Used in `constexpr` Expressions?. For more information, please follow other related articles on the PHP Chinese website!