Function clamp


#include <include/type_safe/bounded_type.hpp>

template <typename T, typename LowerBound, typename UpperBound, typename U>
constexpr auto clamp(const constraints::closed_interval< T, LowerBound, UpperBound > &interval, U &&val) -> typename std::decay< U >::type


Returns a copy of val so that it is in the given [ts::constraints::closed_interval](). \effects If it is not in the interval, returns the bound that is closer to the value. \output_section clamped_type


Lines 470-478 in include/type_safe/bounded_type.hpp.

/// or anything else thrown by the constructor.
/// \notes This is meant for sanitizing user input,
/// using a recoverable error handling strategy.
/// \notes If this function is passed in dynamic values of the same type as `value`,
/// it will create a dynamic bound.
/// Otherwise it must be passed static bounds.
template <typename T, typename U1, typename U2>
constexpr auto sanitize_bounded_exclusive(T&& value, U1&& lower, U2&& upper)
    -> detail::make_bounded_type<throwing_verifier, false, false, T, U1, U2>

Add Discussion as Guest

Log in