Title
constexpr max(initializer_list) vs max_element
Status
c++17
Section
[alg.min.max]
Submitter
Marc Glisse

Created on 2014-02-21.00:00:00 last changed 89 months ago

Messages

Date: 2015-03-29.16:56:20

Proposed resolution:

This wording is relative to N3936.

  1. In [algorithms.general], header <algorithm> synopsis, and [alg.min.max], change as indicated (add constexpr to every signature from the first min_element to the second minmax_element)::

    template<class ForwardIterator>
    constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last);
    template<class ForwardIterator, class Compare>
    constexpr ForwardIterator min_element(ForwardIterator first, ForwardIterator last,
                                          Compare comp);
    […]
    template<class ForwardIterator>
    constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last);
    template<class ForwardIterator, class Compare>
    constexpr ForwardIterator max_element(ForwardIterator first, ForwardIterator last,
                                          Compare comp);
    […]
    template<class ForwardIterator>
    constexpr pair<ForwardIterator, ForwardIterator>
    minmax_element(ForwardIterator first, ForwardIterator last);
    template<class ForwardIterator, class Compare>
    constexpr pair<ForwardIterator, ForwardIterator>
    minmax_element(ForwardIterator first, ForwardIterator last, Compare comp);
    
Date: 2015-03-29.16:56:20

[ 2015-02 Cologne ]

AM: Can we implement this with the C++14 constexpr rules? JM: Yes. AM: Ready? [Yes]

Accepted.

Date: 2014-02-21.00:00:00

As part of the resolution for LWG issue 2350, max(initializer_list) was marked as constexpr. Looking at two implementations of this function (libstdc++ and libc++), both implement it in terms of max_element, which is not marked as constexpr. This is inconsistent and forces some small amount of code duplication in the implementation. Unless we remove constexpr from this overload of max, I believe we should add constexpr to max_element.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2015-05-22 18:31:21adminsetstatus: ready -> wp
2015-03-29 16:56:20adminsetmessages: + msg7267
2015-03-29 16:56:20adminsetstatus: new -> ready
2014-03-24 22:19:13adminsetmessages: + msg6912
2014-02-21 00:00:00admincreate