2350. min, max, and minmax should be constexpr

Section: 28.7.8 [alg.min.max] Status: C++14 Submitter: Ville Voutilainen Opened: 2013-12-15 Last modified: 2016-02-10

Priority: 1

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.

  1. In 28.1 [algorithms.general], header <algorithm> synopsis, and 28.7.8 [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);