7 #if !defined(CNL_IMPL_USED_DIGITS_H)
8 #define CNL_IMPL_USED_DIGITS_H
10 #include "../integer.h"
13 #include <type_traits>
21 template<
bool IsSigned>
22 struct used_digits_signed;
25 struct used_digits_signed<false> {
26 template<
integer Integer>
27 [[nodiscard]] constexpr
auto operator()(Integer
const& value,
int radix)
const ->
int
29 return (value > 0) ? 1 + used_digits_signed<false>{}(value / radix, radix) : 0;
34 struct used_digits_signed<true> {
35 template<
integer Integer>
36 [[nodiscard]] constexpr
auto operator()(Integer
const& value,
int radix)
const
41 return (value < 0) ? used_digits_signed<false>{}(Integer(-1) - value, radix)
42 : used_digits_signed<false>{}(value, radix);
46 template<
integer Integer>
47 [[nodiscard]] constexpr
auto used_digits(
50 return used_digits_signed<std::is_signed<Integer>::value>{}(value, radix);
55 #endif // CNL_IMPL_USED_DIGITS_H