From 5c34e8ae67998c53c1d4016d5b9f4c02917f0ecf Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 26 Nov 2023 22:04:04 +0100 Subject: core,codec,tools: Working on c binding generation --- c++/core/templates.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'c++/core/templates.h') diff --git a/c++/core/templates.h b/c++/core/templates.h index e704f37..e2851a0 100644 --- a/c++/core/templates.h +++ b/c++/core/templates.h @@ -102,4 +102,43 @@ struct ct_multiply { static constexpr T value = V0 * ct_multiply::value; }; +namespace impl { +template +struct ct_convert_digits_table_helper { + static constexpr std::array table = { + '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F' + }; + + static constexpr T value = table[i]; +}; + +template +struct ct_convert_digits_helper { + static constexpr size_t size = ct_convert_digits_helper::size; + static constexpr std::array value = ct_convert_digits_helper::value; +}; + +template +struct ct_convert_digits_helper<0, Base, Digs...> { + static constexpr size_t size = sizeof...(Digs); + static constexpr std::array value = {Digs...}; +}; + +template +struct ct_convert_digits_helper<0, Base> { + static constexpr size_t size = 0; + static constexpr std::array value = {0}; +}; +} + +template +struct ct_convert_to_digits { + static_assert(Base <= 16, "Only conversion up to hex is supported"); + + static constexpr size_t size = impl::ct_convert_digits_helper::size; + static constexpr std::array value = impl::ct_convert_digits_helper::value; +}; } -- cgit v1.2.3