From 834682e65081b4aa51316767674ef62fa7711c55 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 17 Jul 2017 05:44:04 -0700 Subject: [PATCH] Add detail::sum_exceeds --- include/beast/core/detail/clamp.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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