From d5bde6dd1267f8bfe439770164e1e6be7d29f2e5 Mon Sep 17 00:00:00 2001 From: Niek Bouman Date: Sun, 28 Nov 2021 22:05:28 +0100 Subject: [PATCH] Easily allow for custom limb type in literal Thanks @ Anjan Roy --- include/ctbignum/decimal_literals.hpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/include/ctbignum/decimal_literals.hpp b/include/ctbignum/decimal_literals.hpp index 7a99121..1725de4 100644 --- a/include/ctbignum/decimal_literals.hpp +++ b/include/ctbignum/decimal_literals.hpp @@ -51,20 +51,28 @@ constexpr auto chars_to_integer_seq(std::integer_sequence, } //end of detail namespace namespace literals { -template constexpr auto operator"" _Z() { - - using T = uint64_t; // Question: How to elegantly expose the choice of this - // type to the user? - +template constexpr auto generic_limb_literal() { constexpr size_t len = sizeof...(Chars); constexpr size_t N = 1 + (10 * len) / (3 * std::numeric_limits::digits); - auto num = detail::chars_to_integer_seq(std::integer_sequence{}, std::make_index_sequence{}); constexpr auto L = detail::tight_length(num) + (to_big_int(num) == big_int<1, T>{}); return detail::take_first(num, std::make_index_sequence{}); } + +template constexpr auto operator"" _Z() // for backwards compatibility +{ + return generic_limb_literal(); +} + +template constexpr auto operator"" _Z64() { + return generic_limb_literal(); +} + +template constexpr auto operator"" _Z32() { + return generic_limb_literal(); } +} // namespace literals } // end of cbn namespace #endif