Template Function rcppmath::clamp(const T&, const T&, const T&)

Function Documentation

template<class T>
constexpr const T &rcppmath::clamp(const T &v, const T &lo, const T &hi)

If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise returns v. Uses operator< to compare the values.

Warning

Capturing the result of clamp by reference if one of the parameters is rvalue produces a dangling reference if that parameter is returned.

Parameters:
  • v[in] The value to clamp.

  • lo[in] The lower boundary.

  • hi[in] The higher boundary.

Returns:

Reference to lo if v is less than lo, reference to hi if hi is less than v, otherwise reference to v.