forked from boostorg/beast
Add variadic min/max
This commit is contained in:
1 parent
028fda0237
commit
dc6a08d10a
3 files changed
+98
No files matched your search
@@ -180,6 +180,80 @@ struct is_contiguous_container<T, E, void_t<
|
||||
>::type>>: std::true_type
|
||||
{};
|
||||
|
||||
template<class...>
|
||||
struct unwidest_unsigned;
|
||||
|
||||
template<class U0>
|
||||
struct unwidest_unsigned<U0>
|
||||
{
|
||||
using type = U0;
|
||||
};
|
||||
|
||||
template<class U0, class... UN>
|
||||
struct unwidest_unsigned<U0, UN...>
|
||||
{
|
||||
BOOST_STATIC_ASSERT(std::is_unsigned<U0>::value);
|
||||
using type = typename std::conditional<
|
||||
(sizeof(U0) < sizeof(typename unwidest_unsigned<UN...>::type)),
|
||||
U0, typename unwidest_unsigned<UN...>::type>::type;
|
||||
};
|
||||
|
||||
template<class...>
|
||||
struct widest_unsigned;
|
||||
|
||||
template<class U0>
|
||||
struct widest_unsigned<U0>
|
||||
{
|
||||
using type = U0;
|
||||
};
|
||||
|
||||
template<class U0, class... UN>
|
||||
struct widest_unsigned<U0, UN...>
|
||||
{
|
||||
BOOST_STATIC_ASSERT(std::is_unsigned<U0>::value);
|
||||
using type = typename std::conditional<
|
||||
(sizeof(U0) > sizeof(typename widest_unsigned<UN...>::type)),
|
||||
U0, typename widest_unsigned<UN...>::type>::type;
|
||||
};
|
||||
|
||||
template<class U>
|
||||
inline
|
||||
constexpr
|
||||
U
|
||||
min_all(U u)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(std::is_unsigned<U>::value);
|
||||
return u;
|
||||
}
|
||||
|
||||
template<class U0, class U1, class... UN>
|
||||
inline
|
||||
constexpr
|
||||
typename unwidest_unsigned<U0, U1, UN...>::type
|
||||
min_all(U0 u0, U1 u1, UN... un)
|
||||
{
|
||||
return u0 < u1? min_all(u0, un...) : min_all(u1, un...);
|
||||
}
|
||||
|
||||
template<class U>
|
||||
inline
|
||||
constexpr
|
||||
U
|
||||
max_all(U u)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(std::is_unsigned<U>::value);
|
||||
return u;
|
||||
}
|
||||
|
||||
template<class U0, class U1, class... UN>
|
||||
inline
|
||||
constexpr
|
||||
typename widest_unsigned<U0, U1, UN...>::type
|
||||
max_all(U0 u0, U1 u1, UN... un)
|
||||
{
|
||||
return u0 > u1? max_all(u0, un...) : max_all(u1, un...);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user