maths: use SFINAE for round_to instead of assert
This commit is contained in:
parent
cd58dc8cc3
commit
02a42f282e
14
maths.hpp
14
maths.hpp
@ -89,8 +89,18 @@ rootsquare [[gnu::pure]] (T a, T b);
|
||||
//-----------------------------------------------------------------------------
|
||||
// Rounding
|
||||
template <typename T, typename U>
|
||||
typename std::common_type<T, U>::type
|
||||
round_to [[gnu::pure]] (T value, U size);
|
||||
inline
|
||||
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>
|
||||
|
10
maths.ipp
10
maths.ipp
@ -22,16 +22,6 @@
|
||||
|
||||
#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>
|
||||
|
Loading…
Reference in New Issue
Block a user