]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/include/beast/core/detail/clamp.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / core / detail / clamp.hpp
1 //
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7
8 #ifndef BEAST_CORE_DETAIL_CLAMP_HPP
9 #define BEAST_CORE_DETAIL_CLAMP_HPP
10
11 #include <limits>
12 #include <cstdlib>
13
14 namespace beast {
15 namespace detail {
16
17 template<class UInt>
18 static
19 std::size_t
20 clamp(UInt x)
21 {
22 if(x >= (std::numeric_limits<std::size_t>::max)())
23 return (std::numeric_limits<std::size_t>::max)();
24 return static_cast<std::size_t>(x);
25 }
26
27 template<class UInt>
28 static
29 std::size_t
30 clamp(UInt x, std::size_t limit)
31 {
32 if(x >= limit)
33 return limit;
34 return static_cast<std::size_t>(x);
35 }
36
37 } // detail
38 } // beast
39
40 #endif