Loading...
Searching...
No Matches
minmax
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include "type_traits"
namespace cxx
{
// trivial, used to terminate the variadic recursion
template<typename A>
constexpr A const &
min(A const &a)
{ return a; }
template<typename A, typename ...ARGS>
constexpr A const &
min(A const &a1, A const &a2, ARGS const &...a)
{
return min((a1 <= a2) ? a1 : a2, a...);
}
template<typename A, typename ...ARGS>
constexpr A const &
min(cxx::identity_t<A> const &a1,
cxx::identity_t<A> const &a2,
ARGS const &...a)
{
return min<A>((a1 <= a2) ? a1 : a2, a...);
}
// trivial, used to terminate the variadic recursion
template<typename A>
constexpr A const &
max(A const &a)
{ return a; }
template<typename A, typename ...ARGS>
constexpr A const &
max(A const &a1, A const &a2, ARGS const &...a)
{ return max((a1 >= a2) ? a1 : a2, a...); }
template<typename A, typename ...ARGS>
constexpr A const &
max(cxx::identity_t<A> const &a1,
cxx::identity_t<A> const &a2,
ARGS const &...a)
{
return max<A>((a1 >= a2) ? a1 : a2, a...);
}
template< typename T1 >
inline
T1 clamp(T1 v, T1 lo, T1 hi)
{ return min(hi, max(lo, v)); }
};
cxx::clamp
T1 clamp(T1 v, T1 lo, T1 hi)
Limit v to the range given by lo and hi.
Definition minmax:109
cxx
Our C++ library.
Definition arith:11