maths: reduce template verbosity

This commit is contained in:
Danny Robson 2015-11-13 18:00:15 +11:00
parent 8f806b5fa8
commit 5a26793b0a
2 changed files with 29 additions and 19 deletions

View File

@ -117,9 +117,11 @@ digits (const uint32_t &v) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
template <typename T> template <typename T>
T std::enable_if_t<
std::is_integral<T>::value, T
>
round_pow2 (T value) { round_pow2 (T value) {
typedef typename std::enable_if<std::is_integral<T>::value, T>::type return_type; using return_type = std::enable_if_t<std::is_integral<T>::value, T>;
--value; --value;

View File

@ -112,15 +112,23 @@ round_to (T value, U size)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T> template <typename T>
T std::enable_if_t<
std::is_integral<T>::value, T
>
round_pow2 (T value); round_pow2 (T value);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename U> template <typename T, typename U>
constexpr T constexpr std::enable_if_t<
std::is_integral<T>::value &&
std::is_integral<U>::value,
T
>
divup (const T a, const U b) divup (const T a, const U b)
{ return (a + b - 1) / b; } {
return (a + b - 1) / b;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -364,11 +372,11 @@ namespace util {
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <typename T, typename U, typename ...Args> template <typename T, typename U, typename ...Args>
constexpr typename std::enable_if< constexpr std::enable_if_t<
std::is_unsigned<typename std::decay<T>::type>::value == std::is_unsigned<typename std::decay<U>::type>::value && std::is_unsigned<std::decay_t<T>>::value == std::is_unsigned<std::decay_t<U>>::value &&
std::is_integral<typename std::decay<T>::type>::value == std::is_integral<typename std::decay<U>::type>::value, std::is_integral<std::decay_t<T>>::value == std::is_integral<std::decay_t<U>>::value,
typename std::common_type<T,U>::type std::common_type_t<T,U>
>::type >
min (const T a, const U b, Args ...args) min (const T a, const U b, Args ...args)
{ {
return min (a < b ? a : b, std::forward<Args> (args)...); return min (a < b ? a : b, std::forward<Args> (args)...);
@ -385,11 +393,11 @@ namespace util {
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <typename T, typename U, typename ...Args> template <typename T, typename U, typename ...Args>
constexpr typename std::enable_if< constexpr std::enable_if_t<
std::is_unsigned<typename std::decay<T>::type>::value == std::is_unsigned<typename std::decay<U>::type>::value && std::is_unsigned<std::decay_t<T>>::value == std::is_unsigned<std::decay_t<U>>::value &&
std::is_integral<typename std::decay<T>::type>::value == std::is_integral<typename std::decay<U>::type>::value, std::is_integral<std::decay_t<T>>::value == std::is_integral<std::decay_t<U>>::value,
typename std::common_type<T,U>::type std::common_type_t<T,U>
>::type >
max (const T a, const U b, Args ...args) max (const T a, const U b, Args ...args)
{ {
return max (a > b ? a : b, std::forward<Args> (args)...); return max (a > b ? a : b, std::forward<Args> (args)...);