I just noticed that the new standard defines min(a,b)
and max(a,b)
without constexpr
.
Examples from 25.4.7, [
min
and max
are only constant expressions if you call them with constant expressions as arguments. Since they're meant to be much more generally usable than that, you can't make the declaration.
Here's what Wikipedia says about constexpr (emphasis added). I know Wikipedia is not the ultimate reference, but I believe it's correct in this case.
The use of
constexpr
on a function imposes very strict limitations on what that function can do. First, the function must have a non-void return type. Second, the function contents must be of the form: return expr. Third, expr must be a constant expression, after argument substitution. This constant expression may only call other functions defined as constexpr, or it may use other constant expression data variables.