maths: use SFINAE for round_to instead of assert

This commit is contained in:
Danny Robson 2015-11-13 13:47:13 +11:00
parent cd58dc8cc3
commit 02a42f282e
2 changed files with 12 additions and 12 deletions

View File

@ -89,8 +89,18 @@ rootsquare [[gnu::pure]] (T a, T b);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Rounding // Rounding
template <typename T, typename U> template <typename T, typename U>
typename std::common_type<T, U>::type inline
round_to [[gnu::pure]] (T value, U size); typename std::common_type<
std::enable_if_t<std::is_integral<T>::value,T>,
std::enable_if_t<std::is_integral<U>::value,U>
>::type
round_to [[gnu::const]] (T value, U size)
{
if (value % size == 0)
return value;
return value + (size - value % size);
}
template <typename T> template <typename T>

View File

@ -22,16 +22,6 @@
#include <type_traits> #include <type_traits>
//-----------------------------------------------------------------------------
template <typename T, typename U>
typename std::common_type<T,U>::type
round_to (T value, U size) {
static_assert (std::is_integral<T>::value, "align requires integral types");
static_assert (std::is_integral<U>::value, "align requires integral types");
return divup (value, size) * size;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T> template <typename T>