From 02a42f282e7269387f2d79e5c24f755147a47b71 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 13 Nov 2015 13:47:13 +1100 Subject: [PATCH] maths: use SFINAE for round_to instead of assert --- maths.hpp | 14 ++++++++++++-- maths.ipp | 10 ---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/maths.hpp b/maths.hpp index 9a9bfee8..277b19b5 100644 --- a/maths.hpp +++ b/maths.hpp @@ -89,8 +89,18 @@ rootsquare [[gnu::pure]] (T a, T b); //----------------------------------------------------------------------------- // Rounding template -typename std::common_type::type -round_to [[gnu::pure]] (T value, U size); +inline +typename std::common_type< + std::enable_if_t::value,T>, + std::enable_if_t::value,U> +>::type +round_to [[gnu::const]] (T value, U size) +{ + if (value % size == 0) + return value; + + return value + (size - value % size); +} template diff --git a/maths.ipp b/maths.ipp index 7cddf28a..a62eeb7c 100644 --- a/maths.ipp +++ b/maths.ipp @@ -22,16 +22,6 @@ #include -//----------------------------------------------------------------------------- -template -typename std::common_type::type -round_to (T value, U size) { - static_assert (std::is_integral::value, "align requires integral types"); - static_assert (std::is_integral::value, "align requires integral types"); - - return divup (value, size) * size; -} - //----------------------------------------------------------------------------- template