From 81f1a2495f439443e0c0a440f83a68bc8b9a83c6 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 21 Jul 2018 23:39:11 +0100 Subject: [PATCH] Move implementation into a struct. --- include/duckhandy/int_conv.hpp | 37 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/include/duckhandy/int_conv.hpp b/include/duckhandy/int_conv.hpp index ea57ef6..2e71ddd 100644 --- a/include/duckhandy/int_conv.hpp +++ b/include/duckhandy/int_conv.hpp @@ -71,6 +71,26 @@ namespace dhandy { static constexpr L abs(L in) { return (not BecomesUnsigned and std::numeric_limits::is_signed and in < L(0) ? -in : in); } static constexpr CastedType cast (I in) { return static_cast(in); } }; + + template + struct IntConversion { + static constexpr ReversedSizedArray().to_digit(1))>, implem::int_info::max_len + 1> to_ary (I in) { + using RetType = ReversedSizedArray().to_digit(1))>, implem::int_info::max_len + 1>; + using Num = implem::NumberAdaptation; + + const bool was_negative = implem::is_negative(in); + + RetType arr; + arr.push_front('\0'); + do { + arr.push_front(Tr::to_digit(static_cast(Num::abs(Num::cast(in)) % Base))); + in = static_cast(Num::cast(in) / static_cast(Base)); + } while (in); + if (was_negative) + arr.push_front(Tr::minus()); + return arr; + } + }; } //namespace implem template @@ -85,21 +105,8 @@ namespace dhandy { }; template > - constexpr inline ReversedSizedArray().to_digit(1))>, implem::int_info::max_len + 1> int_to_ary (I in) { - using RetType = ReversedSizedArray().to_digit(1))>, implem::int_info::max_len + 1>; - using Num = implem::NumberAdaptation, Base>; - - const bool was_negative = implem::is_negative(in); - - RetType arr; - arr.push_front('\0'); - do { - arr.push_front(Tr::to_digit(static_cast(Num::abs(Num::cast(in)) % Base))); - in = static_cast(Num::cast(in) / static_cast(Base)); - } while (in); - if (was_negative) - arr.push_front(Tr::minus()); - return arr; + constexpr inline auto int_to_ary (I in) { + return implem::IntConversion, Base, Tr>::to_ary(in); } #if !defined(INT_CONV_WITHOUT_HELPERS)