25 Algorithms library [algorithms]

25.5 Sorting and related operations [alg.sorting]

25.5.8 Bounded value [alg.clamp]

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);

Requires: The value of lo shall be no greater than hi. For the first form, type T shall be LessThanComparable (Table [tab:lessthancomparable]).

Returns: lo if v is less than lo, hi if hi is less than v, otherwise v.

Note: If NaN is avoided, T can be a floating-point type.  — end note ]

Complexity: At most two comparisons.