From 8803768363019a81a6aa165d5d3c17a915e21997 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 2 Sep 2024 09:11:33 -0700 Subject: [PATCH] Cleanup base API --- include/fmt/base.h | 104 ++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index fac45a07..2d7d3866 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2109,60 +2109,7 @@ template class counting_buffer : public buffer { return count_ + this->size(); } }; -} // namespace detail -template -FMT_CONSTEXPR void parse_context::do_check_arg_id(int id) { - // Argument id is only checked at compile-time during parsing because - // formatting has its own validation. - if (detail::is_constant_evaluated() && - (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) { - auto ctx = static_cast*>(this); - if (id >= ctx->num_args()) report_error("argument not found"); - } -} - -template -FMT_CONSTEXPR void parse_context::check_dynamic_spec(int arg_id) { - if (detail::is_constant_evaluated() && - (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) { - auto ctx = static_cast*>(this); - ctx->check_dynamic_spec(arg_id); - } -} - -// An output iterator that appends to a buffer. It is used instead of -// back_insert_iterator to reduce symbol sizes and avoid dependency. -template class basic_appender { - private: - detail::buffer* buffer_; - - friend FMT_CONSTEXPR20 auto get_container(basic_appender app) - -> detail::buffer& { - return *app.buffer_; - } - - public: - using iterator_category = int; - using value_type = T; - using difference_type = ptrdiff_t; - using pointer = T*; - using reference = T&; - using container_type = detail::buffer; - FMT_UNCHECKED_ITERATOR(basic_appender); - - FMT_CONSTEXPR basic_appender(detail::buffer& buf) : buffer_(&buf) {} - - FMT_CONSTEXPR20 auto operator=(T c) -> basic_appender& { - buffer_->push_back(c); - return *this; - } - FMT_CONSTEXPR20 auto operator*() -> basic_appender& { return *this; } - FMT_CONSTEXPR20 auto operator++() -> basic_appender& { return *this; } - FMT_CONSTEXPR20 auto operator++(int) -> basic_appender { return *this; } -}; - -namespace detail { template struct is_back_insert_iterator> : std::true_type {}; @@ -2544,6 +2491,57 @@ inline void vprint_mojibake(FILE*, string_view, const format_args&, bool) {} FMT_BEGIN_EXPORT +template +FMT_CONSTEXPR void parse_context::do_check_arg_id(int id) { + // Argument id is only checked at compile-time during parsing because + // formatting has its own validation. + if (detail::is_constant_evaluated() && + (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) { + auto ctx = static_cast*>(this); + if (id >= ctx->num_args()) report_error("argument not found"); + } +} + +template +FMT_CONSTEXPR void parse_context::check_dynamic_spec(int arg_id) { + if (detail::is_constant_evaluated() && + (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) { + auto ctx = static_cast*>(this); + ctx->check_dynamic_spec(arg_id); + } +} + +// An output iterator that appends to a buffer. It is used instead of +// back_insert_iterator to reduce symbol sizes and avoid dependency. +template class basic_appender { + private: + detail::buffer* buffer_; + + friend FMT_CONSTEXPR20 auto get_container(basic_appender app) + -> detail::buffer& { + return *app.buffer_; + } + + public: + using iterator_category = int; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T*; + using reference = T&; + using container_type = detail::buffer; + FMT_UNCHECKED_ITERATOR(basic_appender); + + FMT_CONSTEXPR basic_appender(detail::buffer& buf) : buffer_(&buf) {} + + FMT_CONSTEXPR20 auto operator=(T c) -> basic_appender& { + buffer_->push_back(c); + return *this; + } + FMT_CONSTEXPR20 auto operator*() -> basic_appender& { return *this; } + FMT_CONSTEXPR20 auto operator++() -> basic_appender& { return *this; } + FMT_CONSTEXPR20 auto operator++(int) -> basic_appender { return *this; } +}; + // A formatting argument. Context is a template parameter for the compiled API // where output can be unbuffered. template class basic_format_arg {