28 Algorithms library [algorithms]

28.7 Sorting and related operations [alg.sorting]

28.7.9 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.

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.