This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

### 2369. `constexpr max(initializer_list)` vs `max_element`

Section: 25.8.9 [alg.min.max] Status: C++17 Submitter: Marc Glisse Opened: 2014-02-21 Last modified: 2017-07-30

Priority: 3

View all other issues in [alg.min.max].

View all issues with C++17 status.

Discussion:

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`.

[2015-02 Cologne]

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

Accepted.

Proposed resolution:

This wording is relative to N3936.

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