diff --git a/include/fmt/base.h b/include/fmt/base.h index b08d8267ff9f..bc9cfb2f7056 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2799,17 +2799,10 @@ FMT_API void vprint_mojibake(FILE*, string_view, format_args, bool = false); #ifndef _WIN32 inline void vprint_mojibake(FILE*, string_view, format_args, bool) {} #endif -} // namespace detail - -FMT_BEGIN_EXPORT -// A formatter specialization for natively supported types. -template -struct formatter::value != - detail::type::custom_type>> { +template struct native_formatter { private: - detail::dynamic_format_specs specs_; + dynamic_format_specs specs_; public: using nonlocking = void; @@ -2817,17 +2810,14 @@ struct formatter FMT_CONSTEXPR auto parse(ParseContext& ctx) -> const Char* { if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); - auto type = detail::type_constant::value; - auto end = - detail::parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, type); - if (type == detail::type::char_type) detail::check_char_specs(specs_); + auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE); + if (TYPE == type::char_type) check_char_specs(specs_); return end; } - template ::value, - FMT_ENABLE_IF(U == detail::type::string_type || - U == detail::type::cstring_type || - U == detail::type::char_type)> + template FMT_CONSTEXPR void set_debug_format(bool set = true) { specs_.type = set ? presentation_type::debug : presentation_type::none; } @@ -2836,6 +2826,17 @@ struct formatter decltype(ctx.out()); }; +} // namespace detail + +FMT_BEGIN_EXPORT + +// A formatter specialization for natively supported types. +template +struct formatter::value != + detail::type::custom_type>> + : detail::native_formatter::value> { +}; template struct runtime_format_string { basic_string_view str; diff --git a/include/fmt/format.h b/include/fmt/format.h index 4b0babe80779..3aaee42f6708 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -4321,8 +4321,27 @@ extern template FMT_API auto decimal_point_impl(locale_ref) -> char; extern template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t; #endif // FMT_HEADER_ONLY +template +template +FMT_CONSTEXPR FMT_INLINE auto native_formatter::format( + const T& val, FormatContext& ctx) const -> decltype(ctx.out()) { + if (specs_.width_ref.kind == arg_id_kind::none && + specs_.precision_ref.kind == arg_id_kind::none) { + return write(ctx.out(), val, specs_, ctx.locale()); + } + auto specs = specs_; + handle_dynamic_spec(specs.width, specs.width_ref, ctx); + handle_dynamic_spec(specs.precision, specs.precision_ref, + ctx); + return write(ctx.out(), val, specs, ctx.locale()); +} } // namespace detail +template +struct formatter + : detail::native_formatter {}; + #if FMT_USE_USER_DEFINED_LITERALS inline namespace literals { /** @@ -4412,26 +4431,6 @@ FMT_NODISCARD FMT_INLINE auto formatted_size(const Locale& loc, FMT_END_EXPORT -template -template -FMT_CONSTEXPR FMT_INLINE auto -formatter::value != - detail::type::custom_type>>::format(const T& val, - FormatContext& ctx) - const -> decltype(ctx.out()) { - if (specs_.width_ref.kind == detail::arg_id_kind::none && - specs_.precision_ref.kind == detail::arg_id_kind::none) { - return detail::write(ctx.out(), val, specs_, ctx.locale()); - } - auto specs = specs_; - detail::handle_dynamic_spec(specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec( - specs.precision, specs.precision_ref, ctx); - return detail::write(ctx.out(), val, specs, ctx.locale()); -} - FMT_END_NAMESPACE #ifdef FMT_HEADER_ONLY