diff --git a/include/beast/core/detail/clamp.hpp b/include/beast/core/detail/clamp.hpp index 21afeaaa..6d3a9ed5 100644 --- a/include/beast/core/detail/clamp.hpp +++ b/include/beast/core/detail/clamp.hpp @@ -8,8 +8,9 @@ #ifndef BEAST_CORE_DETAIL_CLAMP_HPP #define BEAST_CORE_DETAIL_CLAMP_HPP -#include #include +#include +#include namespace beast { namespace detail { @@ -34,6 +35,20 @@ clamp(UInt x, std::size_t limit) return static_cast(x); } +// return `true` if x + y > z, which are unsigned +template< + class U1, class U2, class U3> +constexpr +bool +sum_exceeds(U1 x, U2 y, U3 z) +{ + static_assert( + std::is_unsigned::value && + std::is_unsigned::value && + std::is_unsigned::value, ""); + return y > z || x > z - y; +} + } // detail } // beast