Function clamp

Summary

#include "breeze/mathematics/clamp.hpp"

(1) template <typename T>
    constexpr T const  & clamp(T const &value, T const &low, T const &high)

(2) template <typename T, typename Compare>
    constexpr T const  & clamp(T const &value, T const &low, T const &high, Compare comp)

Function overload

Synopsis

#include "breeze/mathematics/clamp.hpp"

template <typename T>
constexpr T const  & clamp(T const &value, T const &low, T const &high)

Description

An implementation of the clamp() templates introduced in C++17.

Precondition
  • T shall be LessThanComparable
  • high shall be no lower than low
Returns
low if value is less than low, high if high is less than value, otherwise value
Complexity
One or two comparisons.
Remarks
  • Returns a reference to value when value is equivalent to one (or both) of the boundary arguments.
  • If NaN is avoided, T can be a floating-point type.

Source

Line 44 in breeze/mathematics/clamp.hpp.

Synopsis

#include "breeze/mathematics/clamp.hpp"

template <typename T, typename Compare>
constexpr T const  & clamp(T const &value, T const &low, T const &high, Compare comp)

Description

An implementation of the clamp() templates introduced in C++17.

Precondition
comp( high, low ) == false
Returns
low if value is less than low, high if high is less than value, otherwise value.
Complexity
One or two comparisons.
Remarks
  • Returns a reference to value when value is equivalent to one (or both) of the boundary arguments.
  • If NaN is avoided, T can be a floating-point type.

Source

Line 68 in breeze/mathematics/clamp.hpp.