2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_CORE_DETAIL_CLAMP_HPP
11 #define BOOST_BEAST_CORE_DETAIL_CLAMP_HPP
15 #include <type_traits>
26 if(x >= (std::numeric_limits<std::size_t>::max)())
27 return (std::numeric_limits<std::size_t>::max)();
28 return static_cast<std::size_t>(x);
34 clamp(UInt x, std::size_t limit)
38 return static_cast<std::size_t>(x);
41 // return `true` if x + y > z, which are unsigned
43 class U1, class U2, class U3>
46 sum_exceeds(U1 x, U2 y, U3 z)
49 std::is_unsigned<U1>::value &&
50 std::is_unsigned<U2>::value &&
51 std::is_unsigned<U3>::value, "");
52 return y > z || x > z - y;