forked from boostorg/beast
41 lines
790 B
C++
41 lines
790 B
C++
//
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
|
|
#ifndef BEAST_CORE_DETAIL_CLAMP_HPP
|
|
#define BEAST_CORE_DETAIL_CLAMP_HPP
|
|
|
|
#include <limits>
|
|
#include <cstdlib>
|
|
|
|
namespace beast {
|
|
namespace detail {
|
|
|
|
template<class UInt>
|
|
static
|
|
std::size_t
|
|
clamp(UInt x)
|
|
{
|
|
if(x >= (std::numeric_limits<std::size_t>::max)())
|
|
return (std::numeric_limits<std::size_t>::max)();
|
|
return static_cast<std::size_t>(x);
|
|
}
|
|
|
|
template<class UInt>
|
|
static
|
|
std::size_t
|
|
clamp(UInt x, std::size_t limit)
|
|
{
|
|
if(x >= limit)
|
|
return limit;
|
|
return static_cast<std::size_t>(x);
|
|
}
|
|
|
|
} // detail
|
|
} // beast
|
|
|
|
#endif
|