From 9b430b9902e90ab2ff0b39b0d652c4cdd6a1b119 Mon Sep 17 00:00:00 2001 From: Andreas Tsouchlos Date: Fri, 26 Nov 2021 14:44:17 +0100 Subject: [PATCH] Passing fmt_data to format_arg functions as constant expression --- inc/format.h | 15 ++++++++------- inc/format_impl.h | 2 +- inc/utility.h | 27 +-------------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/inc/format.h b/inc/format.h index 96596da..1d376ba 100644 --- a/inc/format.h +++ b/inc/format.h @@ -41,20 +41,21 @@ constexpr inline void check_fmt_params() { */ // TODO: Error handling -template -constexpr inline void format_arg(char* dest, fmt_data_t fmt_data, arg_t arg) { -// constexpr auto error_array = get_init_array('f'); +template +constexpr inline void format_arg(char* dest, arg_t arg) { + auto error_array = get_init_array('f'); detail::format_integral(dest, arg, fmt_data); }; // TODO: Error handling -template -constexpr inline void format_arg(char* dest, fmt_data_t fmt_data, arg_t) { +template +constexpr inline void format_arg(char* dest, arg_t) { *(dest) = 'f'; *(dest + fmt_data.length - fmt_data.precision - 1) = '.'; }; // TODO: Error handling -constexpr inline void format_arg(char* dest, fmt_data_t fmt_data, const char* arg) { +template +constexpr inline void format_arg(char* dest, const char* arg) { const std::size_t len = const_strlen(arg); if (len > fmt_data.length) return; @@ -77,7 +78,7 @@ constexpr inline void format_args(char*) { template constexpr inline void format_args(char* dest, first_arg_t first_arg, args_t... args) { - format_arg(dest + fmt_data_array[0].position, fmt_data_array[0], first_arg); + format_arg(dest + fmt_data_array[0].position, first_arg); format_args(dest, args...); } diff --git a/inc/format_impl.h b/inc/format_impl.h index c1e4216..0b9cdff 100644 --- a/inc/format_impl.h +++ b/inc/format_impl.h @@ -90,7 +90,7 @@ constexpr inline void format_integral(char* out, uint_t value, template -constexpr inline void format_integral(char* out, float_t value, +constexpr inline void format_floating_point(char* out, float_t value, fmt_data_t fmt_node) { // TODO } diff --git a/inc/utility.h b/inc/utility.h index 86b2052..0aba545 100644 --- a/inc/utility.h +++ b/inc/utility.h @@ -18,18 +18,8 @@ constexpr inline std::size_t const_pow(std::size_t base, std::size_t pow) { } -//template -//constexpr std::array get_zero_array() { -// std::array result; -// -// for (auto& c : result) -// c = '0'; -// -// return result; -//} - template -constexpr inline std::array get_init_array(char val) { +consteval inline std::array get_init_array(char val) { std::array result; for (auto& c : result) @@ -38,21 +28,6 @@ constexpr inline std::array get_init_array(char val) { return result; } -//template -//constexpr std::array get_init_array() { -// std::array result; -// -// if constexpr (fmt_node.has_zero_padding) { -// for (auto& c : result) -// c = '0'; -// } else { -// for (auto& c : result) -// c = ' '; -// } -// -// return result; -//} - template consteval inline std::size_t count_ast_format_nodes() {