This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++17 status.
min/max/minmax requirementsSection: 26.8.9[alg.min.max]Status:C++17Submitter: Juan SoulieOpened: 2013-01-26Last modified: 2017-07-30
Priority:3
View otheractive issues in [alg.min.max].
View all otherissues in [alg.min.max].
View all issues withC++17 status.
Discussion:
26.8.9[alg.min.max] requires typeT inmin,max, andminmax to beLessThanComparable, but I don't believe this should be required for the versions that take aCompare argument.
Compare being required to induce a strict weak ordering here.Further,min andmax also lack formal complexity guarantees.[2014-06-07 Daniel comments and provides wording]
Certainly, the functions withCompare should not imposeLessThanComparable requirements.
Comparerequirements, I would like to point out that this is requirement is in fact needed, because the specification of the normativeRemarks elements (e.g. "Returns the first argument when the arguments are equivalent.") do depend on the existence of aequivalence relation that can be relied on and this is also consistent with the samestrict weak ordering requirement that is indirectly imposed by theLessThanComparable requirement set for functions referring tooperator< (Let me note that the very sameStrictWeakOrder language concept had intentionally been required for similar reasons during "concept-time" inN2914).[2015-02 Cologne]
JY: We have library-wide requirements thatComp induce a strict weak ordering.
[2015-03-30 Daniel comments]
The Complexity element of p16 is correct, but some others involvinginitializer_list arguments are wrong.
[2015-04-02 Library reflector vote]
The issue has been identified as Tentatively Ready based on six votes in favour.
Proposed resolution:
This wording is relative to N4296.
Change 26.8.9[alg.min.max] as indicated:
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);-1-Requires:For the first form, type
-2-Returns: The smaller value.-3-Remarks: Returns the first argument when the arguments are equivalent.-?-Complexity: Exactly one comparison.Tshall beTypeTisLessThanComparable(Table 18).template<class T> constexpr T min(initializer_list<T> t);template<class T, class Compare> constexpr T min(initializer_list<T> t, Compare comp);-4-Requires:
-5-Returns: […]-6-Remarks: […]-?-Complexity: ExactlyTisshall beLessThanComparableandCopyConstructibleandt.size() > 0.For the first form, typeTshall beLessThanComparable.t.size() - 1comparisons.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);-7-Requires:For the first form, type
-8-Returns: […]-9-Remarks: […]-?-Complexity: Exactly one comparison.Tshall beTypeTisLessThanComparable(Table 18).template<class T> constexpr T max(initializer_list<T> t);template<class T, class Compare> constexpr T max(initializer_list<T> t, Compare comp);-10-Requires:
-11-Returns: […]-12-Remarks: […]-?-Complexity: ExactlyTisshall beLessThanComparableandCopyConstructibleandt.size() > 0.For the first form, typeTshall beLessThanComparable.t.size() - 1comparisons.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);-13-Requires:For the first form, t
-14-Returns: […]-15-Remarks: […]-16-Complexity: Exactly one comparison.TypeTshall beLessThanComparable(Table 18).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);-17-Requires:
-18-Returns: […]-19-Remarks: […]-20-Complexity: At mostTisshall beLessThanComparableandCopyConstructibleandt.size() > 0.For the first form, typeTshall beLessThanComparable.(3/2) * t.size()applications of the corresponding predicate.