Title
min, max, and minmax should be constexpr
Status
c++14
Section
[alg.min.max]
Submitter
Ville Voutilainen

Created on 2013-12-15.00:00:00 last changed 123 months ago

Messages

Date: 2014-02-11.06:32:08

Proposed resolution:

This wording is relative to N3797.

  1. In [algorithms.general], header <algorithm> synopsis, and [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);
    
Date: 2013-12-15.00:00:00

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.

History
Date User Action Args
2014-02-27 17:03:20adminsetstatus: wp -> c++14
2014-02-20 13:52:38adminsetstatus: immediate -> wp
2014-02-12 23:34:43adminsetstatus: new -> immediate
2014-02-11 06:32:08adminsetmessages: + msg6815
2013-12-15 00:00:00admincreate