Add detail::sum_exceeds

This commit is contained in:
Vinnie Falco
2017-07-17 05:44:04 -07:00
parent 22091d5a1c
commit 834682e650

View File

@@ -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