From 5a26793b0a20a4efbcf2860ab0ec1710afc4ff02 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 13 Nov 2015 18:00:15 +1100 Subject: [PATCH] maths: reduce template verbosity --- maths.cpp | 6 ++++-- maths.hpp | 42 +++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/maths.cpp b/maths.cpp index 817e6144..7b675c9d 100644 --- a/maths.cpp +++ b/maths.cpp @@ -117,9 +117,11 @@ digits (const uint32_t &v) { /////////////////////////////////////////////////////////////////////////////// template -T +std::enable_if_t< + std::is_integral::value, T +> round_pow2 (T value) { - typedef typename std::enable_if::value, T>::type return_type; + using return_type = std::enable_if_t::value, T>; --value; diff --git a/maths.hpp b/maths.hpp index e374e2ae..4d551b8f 100644 --- a/maths.hpp +++ b/maths.hpp @@ -112,33 +112,41 @@ round_to (T value, U size) //----------------------------------------------------------------------------- template -T +std::enable_if_t< + std::is_integral::value, T +> round_pow2 (T value); //----------------------------------------------------------------------------- template -constexpr T +constexpr std::enable_if_t< + std::is_integral::value && + std::is_integral::value, + T +> divup (const T a, const U b) - { return (a + b - 1) / b; } +{ + return (a + b - 1) / b; +} /////////////////////////////////////////////////////////////////////////////// // Properties template bool -is_integer (const T& value); +is_integer (const T& value); //----------------------------------------------------------------------------- template unsigned -digits (const T& value); +digits (const T& value); //----------------------------------------------------------------------------- -constexpr int sign (int); -constexpr float sign (float); +constexpr int sign (int); +constexpr float sign (float); constexpr double sign (double); @@ -364,11 +372,11 @@ namespace util { //------------------------------------------------------------------------- template - constexpr typename std::enable_if< - std::is_unsigned::type>::value == std::is_unsigned::type>::value && - std::is_integral::type>::value == std::is_integral::type>::value, - typename std::common_type::type - >::type + constexpr std::enable_if_t< + std::is_unsigned>::value == std::is_unsigned>::value && + std::is_integral>::value == std::is_integral>::value, + std::common_type_t + > min (const T a, const U b, Args ...args) { return min (a < b ? a : b, std::forward (args)...); @@ -385,11 +393,11 @@ namespace util { //------------------------------------------------------------------------- template - constexpr typename std::enable_if< - std::is_unsigned::type>::value == std::is_unsigned::type>::value && - std::is_integral::type>::value == std::is_integral::type>::value, - typename std::common_type::type - >::type + constexpr std::enable_if_t< + std::is_unsigned>::value == std::is_unsigned>::value && + std::is_integral>::value == std::is_integral>::value, + std::common_type_t + > max (const T a, const U b, Args ...args) { return max (a > b ? a : b, std::forward (args)...);