Per cplusplus.com, here, the default C++11 prototype for std::max()
is:
template <class T>
const T& max(const T& a, const T& b);
In the C++14 version, however constexpr
was added:
template <class T>
constexpr const T& max(const T& a, const T& b);
Why is constexpr
here and what does it add?
Note on possible duplicate
I think my question is not a duplicate of this one (Difference between `constexpr` and `const`), because I am asking about a very specific usage of constexpr
, whereas that question is asking "tell me everything you know about const and constexpr". The specific usage is extremely hard to dig out of those massive answers because that other question isn't pointed enough and specific enough to drive the answers right to the point of my question.
Related:
- This info (this question plus what I learned from my answer and others here) just went into my answer here: MIN and MAX in C
- Difference between `constexpr` and `const`
- std::max() and std::min() not constexpr