This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++14 status.
min, max, and minmax should be constexprSection: 26.8.9 [alg.min.max] Status: C++14 Submitter: Ville Voutilainen Opened: 2013-12-15 Last modified: 2016-01-28
Priority: 1
View other active issues in [alg.min.max].
View all other issues in [alg.min.max].
View all issues with C++14 status.
Discussion:
Having min, max, and minmax constexpr
was a large part of the motivation to allow reference-to-const arguments for
constexpr functions as per
N3039.
Furthermore, initializer_lists are immutable and not-movable-from
for large part in order to allow using them in constexpr contexts
and other hoisting-optimizations. In N3797
version of the draft none of these functions are constexpr, and they should be made
constexpr.
Proposed resolution:
This wording is relative to N3797.
In 26.1 [algorithms.general], header <algorithm> synopsis, and 26.8.9 [alg.min.max],
change as indicated (add constexpr to every signature before min_element):
template<class T> constexpr const T& min(const T& a, const T& b); template<class T, class Compare> constexpr const T& min(const T& a, const T& b, Compare comp); […] template<class T> constexpr T min(initializer_list<T> t); template<class T, class Compare> constexpr T min(initializer_list<T> t, Compare comp); […] template<class T> constexpr const T& max(const T& a, const T& b); template<class T, class Compare> constexpr const T& max(const T& a, const T& b, Compare comp); […] template<class T> constexpr T max(initializer_list<T> t); template<class T, class Compare> constexpr T max(initializer_list<T> t, Compare comp); […] template<class T> constexpr pair<const T&, const T&> minmax(const T& a, const T& b); template<class T, class Compare> constexpr pair<const T&, const T&> minmax(const T& a, const T& b, Compare comp); […] template<class T> constexpr pair<T, T> minmax(initializer_list<T> t); template<class T, class Compare> constexpr pair<T, T> minmax(initializer_list<T> t, Compare comp);