Title
clamp misses preconditions and has extraneous condition on result
Status
c++17
Section
[alg.clamp]
Submitter
Martin Moene

Created on 2016-03-23.00:00:00 last changed 89 months ago

Messages

Date: 2016-06-22.23:39:35

Proposed resolution:

This wording is relative to N4582.

  1. Edit [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 lo shall be no greater than hi. For the first form, type T shall be LessThanComparable (Table 18).

    -2- Returns: lo if v is less than lo, hi if hi is less than v, otherwise vThe larger value of v and lo if v is smaller than hi, otherwise the smaller value of v and hi.

    -3- NoteRemarks: If NaN is avoided, T can be a floating point type Returns the first argument when it is equivalent to one of the boundary arguments.

    -4- Complexity: At most two comparisons.

Date: 2017-02-02.00:41:18

[ 2016-05 Issues Telecon ]

Reworded p3 slightly.

Date: 2016-06-22.23:39:35

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]:

  1. Edit [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 lo shall be no greater than hi. For the first form, type T shall be LessThanComparable (Table 18).

    -2- Returns: lo if v is less than lo, hi if hi is less than v, otherwise vThe larger value of v and lo if v is smaller than hi, otherwise the smaller value of v and hi.

    -3- NoteRemarks: If NaN is avoided, T can be float or doubleReturns the first argument when it is equivalent to one of the boundary arguments.

    -4- Complexity: At most two comparisons.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2016-06-28 12:50:44adminsetstatus: ready -> wp
2016-05-22 15:38:38adminsetmessages: + msg8135
2016-05-22 15:38:38adminsetstatus: new -> ready
2016-05-06 16:48:25adminsetmessages: + msg8077
2016-03-23 00:00:00admincreate