Title
Inconsistently named return type for ranges::minmax_element
Status
c++20
Section
[algorithm.syn]
Submitter
Casey Carter

Created on 2018-12-21.00:00:00 last changed 46 months ago

Messages

Date: 2019-01-12.16:18:42

Proposed resolution:

This wording is relative to N4791.

  1. Change [algorithm.syn] as indicated, and adjust the declarations of std::ranges::minmax_element in [alg.min.max] to agree:

    […]
    template<class ExecutionPolicy, class ForwardIterator, class Compare>
      pair<ForwardIterator, ForwardIterator>
        minmax_element(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
                       ForwardIterator first, ForwardIterator last, Compare comp);
    
    namespace ranges {
      template<class I>
      using minmax_element_result = minmax_result<I>;
    
      template<ForwardIterator I, Sentinel<I> S, class Proj = identity,
               IndirectStrictWeakOrder<projected<I, Proj>> Comp = ranges::less<>>
        constexpr minmax_element_result<I>
          minmax_element(I first, S last, Comp comp = {}, Proj proj = {});
      template<ForwardRange R, class Proj = identity,
               IndirectStrictWeakOrder<projected<iterator_t<R>, Proj>> Comp = ranges::less<>>
        constexpr minmax_element_result<safe_iterator_t<R>>
          minmax_element(R&& r, Comp comp = {}, Proj proj = {});
    }
    
    // [alg.clamp], bounded value
    […]
    
Date: 2019-01-11.00:00:00

[ 2019-01-11 Status to Tentatively Ready after five positive votes on the reflector. ]

During that reflector discussion several contributers questioned the choice of alias templates to denote algorithm result types or particular aspects of it. Since this approach had been approved by LEWG before, it was suggested to those opponents to instead write a paper, because changing this as part of this issue would be a design change that would require a more global fixing approach.

Date: 2018-12-21.00:00:00

The overloads of std::ranges::minmax_element are specified to return std::ranges::minmax_result, which is inconsistent with the intended design. When an algorithm foo returns an aggregate of multiple results, the return type should be named foo_result. The spec should introduce an alias minmax_element_result for minmax_result and use that alias as the return type of the std::ranges::minmax_element overloads.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2019-02-26 17:40:23adminsetstatus: voting -> wp
2019-01-21 04:50:04adminsetstatus: ready -> voting
2019-01-12 16:18:42adminsetmessages: + msg10277
2019-01-12 16:18:42adminsetstatus: new -> ready
2018-12-21 21:22:01adminsetmessages: + msg10272
2018-12-21 00:00:00admincreate