mirror of
https://github.com/boostorg/beast.git
synced 2025-08-03 14:54:32 +02:00
Add detail::sum_exceeds
This commit is contained in:
@@ -8,8 +8,9 @@
|
||||
#ifndef BEAST_CORE_DETAIL_CLAMP_HPP
|
||||
#define BEAST_CORE_DETAIL_CLAMP_HPP
|
||||
|
||||
#include <limits>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
namespace beast {
|
||||
namespace detail {
|
||||
@@ -34,6 +35,20 @@ clamp(UInt x, std::size_t limit)
|
||||
return static_cast<std::size_t>(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<U1>::value &&
|
||||
std::is_unsigned<U2>::value &&
|
||||
std::is_unsigned<U3>::value, "");
|
||||
return y > z || x > z - y;
|
||||
}
|
||||
|
||||
} // detail
|
||||
} // beast
|
||||
|
||||
|
Reference in New Issue
Block a user