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.
clamp
misses preconditions and has extraneous condition on resultSection: 26.8.10 [alg.clamp] Status: C++17 Submitter: Martin Moene Opened: 2016-03-23 Last modified: 2017-07-30
Priority: 0
View all issues with C++17 status.
Discussion:
In Jacksonville (2016), P0025R0 was voted in instead of the intended P0025R1. This report contains the necessary mending along with two other improvements.
This report:adds the precondition that misses from P0025R0 but is in P0025R1,
corrects the returns: specification that contains an extraneous condition,
replaces the now superfluous remark with a note on usage of clamp with float
or double
.
Thanks to Carlo Assink and David Gaarenstroom for making us aware of the extraneous condition in the returns: specification and for suggesting the fix and to Jeffrey Yasskin for suggesting to add a note like p3.
Previous resolution [SUPERSEDED]:
Edit 26.8.10 [alg.clamp] as indicated:
template<class T> constexpr const T& clamp(const T& v, const T& lo, const T& hi); template<class T, class Compare> constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);-1- Requires: The value of
-2- Returns:lo
shall be no greater thanhi
. For the first form, typeT
shall beLessThanComparable
(Table 18).lo
ifv
is less thanlo
,hi
ifhi
is less thanv
, otherwisev
The larger value of. -3- Notev
andlo
ifv
is smaller thanhi
, otherwise the smaller value ofv
andhi
Remarks: If NaN is avoided,T
can befloat
ordouble
Returns the first argument when it is equivalent to one of the boundary arguments. -4- Complexity: At most two comparisons.
[2016-05 Issues Telecon]
Reworded p3 slightly.
Proposed resolution:
This wording is relative to N4582.
Edit 26.8.10 [alg.clamp] as indicated:
template<class T> constexpr const T& clamp(const T& v, const T& lo, const T& hi); template<class T, class Compare> constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp);-1- Requires: The value of
-2- Returns:lo
shall be no greater thanhi
. For the first form, typeT
shall beLessThanComparable
(Table 18).lo
ifv
is less thanlo
,hi
ifhi
is less thanv
, otherwisev
The larger value of. -3- Notev
andlo
ifv
is smaller thanhi
, otherwise the smaller value ofv
andhi
Remarks: If NaN is avoided,T
can be a floating point typeReturns the first argument when it is equivalent to one of the boundary arguments. -4- Complexity: At most two comparisons.