From 158893b384aeb71f4a2ed7d33dd1fb9b488bc487 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 6 Sep 2024 13:20:44 -0700 Subject: [PATCH] Cleanup --- include/fmt/args.h | 6 ++---- include/fmt/color.h | 9 ++++----- include/fmt/format.h | 11 ++++------- include/fmt/os.h | 4 ++-- include/fmt/ostream.h | 19 +++++-------------- include/fmt/ranges.h | 23 +++++++---------------- 6 files changed, 24 insertions(+), 48 deletions(-) diff --git a/include/fmt/args.h b/include/fmt/args.h index 287856c9..1eb9c538 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -17,7 +17,6 @@ #include "format.h" // std_string_view FMT_BEGIN_NAMESPACE - namespace detail { template struct is_reference_wrapper : std::false_type {}; @@ -72,8 +71,7 @@ class dynamic_arg_list { * It can be implicitly converted into `fmt::basic_format_args` for passing * into type-erased formatting functions such as `fmt::vformat`. */ -template -class dynamic_format_arg_store { +template class dynamic_format_arg_store { private: using char_type = typename Context::char_type; @@ -201,7 +199,7 @@ class dynamic_format_arg_store { void clear() { data_.clear(); named_info_.clear(); - dynamic_args_ = detail::dynamic_arg_list(); + dynamic_args_ = {}; } /// Reserves space to store at least `new_cap` arguments including diff --git a/include/fmt/color.h b/include/fmt/color.h index d584ce3f..1e785f73 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -441,9 +441,9 @@ template struct styled_arg : detail::view { }; template -void vformat_to( - buffer& buf, const text_style& ts, basic_string_view format_str, - basic_format_args>> args) { +void vformat_to(buffer& buf, const text_style& ts, + basic_string_view fmt, + basic_format_args> args) { bool has_style = false; if (ts.has_emphasis()) { has_style = true; @@ -460,10 +460,9 @@ void vformat_to( auto background = detail::make_background_color(ts.get_background()); buf.append(background.begin(), background.end()); } - detail::vformat_to(buf, format_str, args, {}); + detail::vformat_to(buf, fmt, args); if (has_style) detail::reset_color(buf); } - } // namespace detail inline void vprint(FILE* f, const text_style& ts, string_view fmt, diff --git a/include/fmt/format.h b/include/fmt/format.h index e46c9168..ad7981cb 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -143,7 +143,7 @@ FMT_END_NAMESPACE #ifndef FMT_USE_USER_LITERALS // EDG based compilers (Intel, NVIDIA, Elbrus, etc), GCC and MSVC support UDLs. # if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION || \ - FMT_MSC_VERSION >= 1900) && \ + FMT_MSC_VERSION >= 1900) && \ (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= /* UDL feature */ 480) # define FMT_USE_USER_LITERALS 1 # else @@ -3807,8 +3807,8 @@ template struct udl_arg { return {str, std::forward(value)}; } }; -# endif // FMT_USE_NONTYPE_TEMPLATE_ARGS -#endif // FMT_USE_USER_LITERALS +# endif // FMT_USE_NONTYPE_TEMPLATE_ARGS +#endif // FMT_USE_USER_LITERALS template struct format_handler { parse_context parse_ctx; @@ -3857,7 +3857,6 @@ template struct format_handler { }; // DEPRECATED! -// Use vformat_args and avoid type_identity to keep symbols short. template struct vformat_args { using type = basic_format_args>; }; @@ -4349,8 +4348,7 @@ template ::value)> auto vformat_to(OutputIt out, const Locale& loc, string_view fmt, format_args args) -> OutputIt { - using detail::get_buffer; - auto&& buf = get_buffer(out); + auto&& buf = detail::get_buffer(out); detail::vformat_to(buf, fmt, args, detail::locale_ref(loc)); return detail::get_iterator(buf, out); } @@ -4374,7 +4372,6 @@ FMT_NODISCARD FMT_INLINE auto formatted_size(const Locale& loc, } FMT_END_EXPORT - FMT_END_NAMESPACE #ifdef FMT_HEADER_ONLY diff --git a/include/fmt/os.h b/include/fmt/os.h index 91afeee8..9e016536 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -147,8 +147,8 @@ FMT_API std::system_error vwindows_error(int error_code, string_view format_str, * } */ template -auto windows_error(int error_code, string_view message, - const T&... args) -> std::system_error { +auto windows_error(int error_code, string_view message, const T&... args) + -> std::system_error { return vwindows_error(error_code, message, vargs{{args...}}); } diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 3a24ca03..d1ec65ab 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -148,25 +148,14 @@ constexpr auto streamed(const T& value) -> detail::streamed_view { return {value}; } -namespace detail { - -inline void vprint_directly(std::ostream& os, string_view format_str, - format_args args) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, format_str, args); - detail::write_buffer(os, buffer); -} - -} // namespace detail - FMT_EXPORT template void vprint(std::basic_ostream& os, basic_string_view> fmt, typename detail::vformat_args::type args) { auto buffer = basic_memory_buffer(); detail::vformat_to(buffer, fmt, args); - if (detail::write_ostream_unicode(os, {buffer.data(), buffer.size()})) return; - detail::write_buffer(os, buffer); + if (!detail::write_ostream_unicode(os, {buffer.data(), buffer.size()})) + detail::write_buffer(os, buffer); } /** @@ -180,7 +169,9 @@ FMT_EXPORT template void print(std::ostream& os, format_string fmt, T&&... args) { fmt::vargs vargs = {{args...}}; if (FMT_USE_UTF8) return vprint(os, fmt, vargs); - detail::vprint_directly(os, fmt, vargs); + auto buffer = memory_buffer(); + detail::vformat_to(buffer, fmt, vargs); + detail::write_buffer(os, buffer); } FMT_EXPORT diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 8fdffaed..6175fc8b 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -44,18 +44,6 @@ template class is_set { !std::is_void(nullptr))>::value && !is_map::value; }; -template struct conditional_helper {}; - -template struct is_range_ : std::false_type {}; - -#if !FMT_MSC_VERSION || FMT_MSC_VERSION > 1800 - -# define FMT_DECLTYPE_RETURN(val) \ - ->decltype(val) { return val; } \ - static_assert( \ - true, "") // This makes it so that a semicolon is required after the - // macro, which helps clang-format handle the formatting. - // C array overload template auto range_begin(const T (&arr)[N]) -> const T* { @@ -76,9 +64,13 @@ struct has_member_fn_begin_end_t().begin()), // Member function overloads. template -auto range_begin(T&& rng) FMT_DECLTYPE_RETURN(static_cast(rng).begin()); +auto range_begin(T&& rng) -> decltype(static_cast(rng).begin()) { + return static_cast(rng).begin(); +} template -auto range_end(T&& rng) FMT_DECLTYPE_RETURN(static_cast(rng).end()); +auto range_end(T&& rng) -> decltype(static_cast(rng).end()) { + return static_cast(rng).end(); +} // ADL overloads. Only participate in overload resolution if member functions // are not found. @@ -115,12 +107,11 @@ struct has_mutable_begin_end< // SFINAE properly unless there are distinct types int>> : std::true_type {}; +template struct is_range_ : std::false_type {}; template struct is_range_ : std::integral_constant::value || has_mutable_begin_end::value)> {}; -# undef FMT_DECLTYPE_RETURN -#endif // tuple_size and tuple_element check. template class is_tuple_like_ {