diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 02eb8d46..fd9c4d5e 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1655,7 +1655,7 @@ OutputIt format_duration_value(OutputIt out, Rep val, int) { template ::value)> OutputIt format_duration_value(OutputIt out, Rep val, int precision) { - auto specs = basic_format_specs(); + auto specs = format_specs(); specs.precision = precision; specs.type = precision >= 0 ? presentation_type::fixed_lower : presentation_type::general_lower; @@ -1991,7 +1991,7 @@ template struct formatter { template struct formatter, Char> { private: - basic_format_specs specs; + format_specs specs; int precision = -1; using arg_ref_type = detail::arg_ref; arg_ref_type width_ref; diff --git a/include/fmt/core.h b/include/fmt/core.h index 1755d1ed..96e13151 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2146,7 +2146,7 @@ enum class presentation_type : unsigned char { }; // Format specifiers for built-in and string types. -template struct basic_format_specs { +template struct format_specs { int width; int precision; presentation_type type; @@ -2156,7 +2156,7 @@ template struct basic_format_specs { bool localized : 1; detail::fill_t fill; - constexpr basic_format_specs() + constexpr format_specs() : width(0), precision(-1), type(presentation_type::none), @@ -2166,8 +2166,6 @@ template struct basic_format_specs { localized(false) {} }; -using format_specs = basic_format_specs; - FMT_BEGIN_DETAIL_NAMESPACE enum class arg_id_kind { none, index, name }; @@ -2200,8 +2198,7 @@ template struct arg_ref { // Format specifiers with width and precision resolved at formatting rather // than parsing time to allow re-using the same parsed specifiers with // different sets of arguments (precompilation of format strings). -template -struct dynamic_format_specs : basic_format_specs { +template struct dynamic_format_specs : format_specs { arg_ref width_ref; arg_ref precision_ref; }; @@ -2217,13 +2214,13 @@ template struct dynamic_spec { }; }; -// A format specifier handler that sets fields in basic_format_specs. +// A format specifier handler that sets fields in format_specs. template class specs_setter { protected: - basic_format_specs& specs_; + format_specs& specs_; public: - explicit FMT_CONSTEXPR specs_setter(basic_format_specs& specs) + explicit FMT_CONSTEXPR specs_setter(format_specs& specs) : specs_(specs) {} FMT_CONSTEXPR void on_align(align_t align) { specs_.align = align; } @@ -2783,7 +2780,7 @@ FMT_CONSTEXPR void check_int_type_spec(presentation_type type, // Checks char specs and returns true if the type spec is char (and not int). template -FMT_CONSTEXPR auto check_char_specs(const basic_format_specs& specs, +FMT_CONSTEXPR auto check_char_specs(const format_specs& specs, ErrorHandler&& eh = {}) -> bool { if (specs.type != presentation_type::none && specs.type != presentation_type::chr && @@ -2815,7 +2812,7 @@ struct float_specs { }; template -FMT_CONSTEXPR auto parse_float_type_spec(const basic_format_specs& specs, +FMT_CONSTEXPR auto parse_float_type_spec(const format_specs& specs, ErrorHandler&& eh = {}) -> float_specs { auto result = float_specs(); diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 97123fb2..fa7b1e38 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -117,7 +117,7 @@ template FMT_FUNC Char decimal_point_impl(locale_ref) { #endif FMT_FUNC auto write_loc(appender out, loc_value value, - const format_specs& specs, locale_ref loc) -> bool { + const format_specs<>& specs, locale_ref loc) -> bool { #ifndef FMT_STATIC_THOUSANDS_SEPARATOR auto locale = loc.get(); // We cannot use the num_put facet because it may produce output in @@ -142,7 +142,7 @@ template format_facet::format_facet(Locale& loc) { template <> FMT_API FMT_FUNC auto format_facet::do_put( - appender out, loc_value val, const format_specs& specs) const -> bool { + appender out, loc_value val, const format_specs<>& specs) const -> bool { return val.visit( detail::loc_writer<>{out, specs, separator_, grouping_, decimal_point_}); } diff --git a/include/fmt/format.h b/include/fmt/format.h index cc2cad1a..ab1db08a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1043,7 +1043,7 @@ template class format_facet : public Locale::facet { protected: virtual auto do_put(appender out, loc_value val, - const format_specs& specs) const -> bool; + const format_specs<>& specs) const -> bool; public: static FMT_API typename Locale::id id; @@ -1056,7 +1056,7 @@ template class format_facet : public Locale::facet { grouping_(g.begin(), g.end()), decimal_point_(decimal_point) {} - auto put(appender out, loc_value val, const format_specs& specs) const + auto put(appender out, loc_value val, const format_specs<>& specs) const -> bool { return do_put(out, val, specs); } @@ -1664,8 +1664,7 @@ FMT_NOINLINE FMT_CONSTEXPR auto fill(OutputIt it, size_t n, // width: output display width in (terminal) column positions. template -FMT_CONSTEXPR auto write_padded(OutputIt out, - const basic_format_specs& specs, +FMT_CONSTEXPR auto write_padded(OutputIt out, const format_specs& specs, size_t size, size_t width, F&& f) -> OutputIt { static_assert(align == align::left || align == align::right, ""); unsigned spec_width = to_unsigned(specs.width); @@ -1684,15 +1683,14 @@ FMT_CONSTEXPR auto write_padded(OutputIt out, template -constexpr auto write_padded(OutputIt out, const basic_format_specs& specs, +constexpr auto write_padded(OutputIt out, const format_specs& specs, size_t size, F&& f) -> OutputIt { return write_padded(out, specs, size, size, f); } template FMT_CONSTEXPR auto write_bytes(OutputIt out, string_view bytes, - const basic_format_specs& specs) - -> OutputIt { + const format_specs& specs) -> OutputIt { return write_padded( out, specs, bytes.size(), [bytes](reserve_iterator it) { const char* data = bytes.data(); @@ -1701,8 +1699,8 @@ FMT_CONSTEXPR auto write_bytes(OutputIt out, string_view bytes, } template -auto write_ptr(OutputIt out, UIntPtr value, - const basic_format_specs* specs) -> OutputIt { +auto write_ptr(OutputIt out, UIntPtr value, const format_specs* specs) + -> OutputIt { int num_digits = count_digits<4>(value); auto size = to_unsigned(num_digits) + size_t(2); auto write = [=](reserve_iterator it) { @@ -1875,8 +1873,7 @@ auto write_escaped_char(OutputIt out, Char v) -> OutputIt { template FMT_CONSTEXPR auto write_char(OutputIt out, Char value, - const basic_format_specs& specs) - -> OutputIt { + const format_specs& specs) -> OutputIt { bool is_debug = specs.type == presentation_type::debug; return write_padded(out, specs, 1, [=](reserve_iterator it) { if (is_debug) return write_escaped_char(it, value); @@ -1886,8 +1883,8 @@ FMT_CONSTEXPR auto write_char(OutputIt out, Char value, } template FMT_CONSTEXPR auto write(OutputIt out, Char value, - const basic_format_specs& specs, - locale_ref loc = {}) -> OutputIt { + const format_specs& specs, locale_ref loc = {}) + -> OutputIt { return check_char_specs(specs) ? write_char(out, value, specs) : write(out, static_cast(value), specs, loc); @@ -1900,7 +1897,7 @@ template struct write_int_data { size_t padding; FMT_CONSTEXPR write_int_data(int num_digits, unsigned prefix, - const basic_format_specs& specs) + const format_specs& specs) : size((prefix >> 24) + to_unsigned(num_digits)), padding(0) { if (specs.align == align::numeric) { auto width = to_unsigned(specs.width); @@ -1922,7 +1919,7 @@ template struct write_int_data { template FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, int num_digits, unsigned prefix, - const basic_format_specs& specs, + const format_specs& specs, W write_digits) -> OutputIt { // Slightly faster check for specs.width == 0 && specs.precision == -1. if ((specs.width | (specs.precision + 1)) == 0) { @@ -2011,7 +2008,7 @@ template class digit_grouping { // Writes a decimal integer with digit grouping. template auto write_int(OutputIt out, UInt value, unsigned prefix, - const basic_format_specs& specs, + const format_specs& specs, const digit_grouping& grouping) -> OutputIt { static_assert(std::is_same, UInt>::value, ""); int num_digits = count_digits(value); @@ -2030,10 +2027,10 @@ auto write_int(OutputIt out, UInt value, unsigned prefix, } // Writes a localized value. -FMT_API auto write_loc(appender out, loc_value value, const format_specs& specs, - locale_ref loc) -> bool; +FMT_API auto write_loc(appender out, loc_value value, + const format_specs<>& specs, locale_ref loc) -> bool; template -inline auto write_loc(OutputIt, loc_value, const basic_format_specs&, +inline auto write_loc(OutputIt, loc_value, const format_specs&, locale_ref) -> bool { return false; } @@ -2066,7 +2063,7 @@ FMT_CONSTEXPR auto make_write_int_arg(T value, sign_t sign) template struct loc_writer { buffer_appender out; - const basic_format_specs& specs; + const format_specs& specs; std::basic_string sep; std::string grouping; std::basic_string decimal_point; @@ -2087,7 +2084,7 @@ template struct loc_writer { template FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg arg, - const basic_format_specs& specs, + const format_specs& specs, locale_ref) -> OutputIt { static_assert(std::is_same>::value, ""); auto abs_value = arg.abs_value; @@ -2143,7 +2140,7 @@ FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg arg, } template FMT_CONSTEXPR FMT_NOINLINE auto write_int_noinline( - OutputIt out, write_int_arg arg, const basic_format_specs& specs, + OutputIt out, write_int_arg arg, const format_specs& specs, locale_ref loc) -> OutputIt { return write_int(out, arg, specs, loc); } @@ -2152,7 +2149,7 @@ template ::value && std::is_same>::value)> FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value, - const basic_format_specs& specs, + const format_specs& specs, locale_ref loc) -> OutputIt { if (specs.localized && write_loc(out, value, specs, loc)) return out; return write_int_noinline(out, make_write_int_arg(value, specs.sign), specs, @@ -2164,7 +2161,7 @@ template ::value && !std::is_same>::value)> FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value, - const basic_format_specs& specs, + const format_specs& specs, locale_ref loc) -> OutputIt { if (specs.localized && write_loc(out, value, specs, loc)) return out; return write_int(out, make_write_int_arg(value, specs.sign), specs, loc); @@ -2212,7 +2209,7 @@ class counting_iterator { template FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, - const basic_format_specs& specs) -> OutputIt { + const format_specs& specs) -> OutputIt { auto data = s.data(); auto size = s.size(); if (specs.precision >= 0 && to_unsigned(specs.precision) < size) @@ -2234,14 +2231,14 @@ FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, template FMT_CONSTEXPR auto write(OutputIt out, basic_string_view> s, - const basic_format_specs& specs, locale_ref) + const format_specs& specs, locale_ref) -> OutputIt { check_string_type_spec(specs.type); return write(out, s, specs); } template FMT_CONSTEXPR auto write(OutputIt out, const Char* s, - const basic_format_specs& specs, locale_ref) + const format_specs& specs, locale_ref) -> OutputIt { return check_cstring_type_spec(specs.type) ? write(out, basic_string_view(s), specs, {}) @@ -2272,7 +2269,7 @@ FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt { template FMT_CONSTEXPR20 auto write_nonfinite(OutputIt out, bool isnan, - basic_format_specs specs, + format_specs specs, const float_specs& fspecs) -> OutputIt { auto str = isnan ? (fspecs.upper ? "NAN" : "nan") : (fspecs.upper ? "INF" : "inf"); @@ -2396,7 +2393,7 @@ FMT_CONSTEXPR20 auto write_significand(OutputIt out, T significand, template > FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f, - const basic_format_specs& specs, + const format_specs& specs, float_specs fspecs, locale_ref loc) -> OutputIt { auto significand = f.significand; @@ -2515,7 +2512,7 @@ template class fallback_digit_grouping { template FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f, - const basic_format_specs& specs, + const format_specs& specs, float_specs fspecs, locale_ref loc) -> OutputIt { if (is_constant_evaluated()) { @@ -3302,7 +3299,7 @@ FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs, } template FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, - basic_format_specs specs, locale_ref loc) + format_specs specs, locale_ref loc) -> OutputIt { float_specs fspecs = parse_float_type_spec(specs); fspecs.sign = specs.sign; @@ -3351,9 +3348,8 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, T value, template ::value)> -FMT_CONSTEXPR20 auto write(OutputIt out, T value, - basic_format_specs specs, locale_ref loc = {}) - -> OutputIt { +FMT_CONSTEXPR20 auto write(OutputIt out, T value, format_specs specs, + locale_ref loc = {}) -> OutputIt { if (const_check(!is_supported_floating_point(value))) return out; return specs.localized && write_loc(out, value, specs, loc) ? out @@ -3363,8 +3359,7 @@ FMT_CONSTEXPR20 auto write(OutputIt out, T value, template ::value)> FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt { - if (is_constant_evaluated()) - return write(out, value, basic_format_specs()); + if (is_constant_evaluated()) return write(out, value, format_specs()); if (const_check(!is_supported_floating_point(value))) return out; auto fspecs = float_specs(); @@ -3373,7 +3368,7 @@ FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt { value = -value; } - constexpr auto specs = basic_format_specs(); + constexpr auto specs = format_specs(); using floaty = conditional_t::value, double, T>; using floaty_uint = typename dragonbox::float_info::carrier_uint; floaty_uint mask = exponent_mask(); @@ -3388,12 +3383,12 @@ template ::value && !is_fast_float::value)> inline auto write(OutputIt out, T value) -> OutputIt { - return write(out, value, basic_format_specs()); + return write(out, value, format_specs()); } template -auto write(OutputIt out, monostate, basic_format_specs = {}, - locale_ref = {}) -> OutputIt { +auto write(OutputIt out, monostate, format_specs = {}, locale_ref = {}) + -> OutputIt { FMT_ASSERT(false, ""); return out; } @@ -3427,8 +3422,8 @@ FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt { template ::value)> FMT_CONSTEXPR auto write(OutputIt out, T value, - const basic_format_specs& specs = {}, - locale_ref = {}) -> OutputIt { + const format_specs& specs = {}, locale_ref = {}) + -> OutputIt { return specs.type != presentation_type::none && specs.type != presentation_type::string ? write(out, value ? 1 : 0, specs, {}) @@ -3455,9 +3450,8 @@ FMT_CONSTEXPR_CHAR_TRAITS auto write(OutputIt out, const Char* value) template ::value)> -auto write(OutputIt out, const T* value, - const basic_format_specs& specs = {}, locale_ref = {}) - -> OutputIt { +auto write(OutputIt out, const T* value, const format_specs& specs = {}, + locale_ref = {}) -> OutputIt { check_pointer_type_spec(specs.type, error_handler()); return write_ptr(out, bit_cast(value), &specs); } @@ -3513,7 +3507,7 @@ template struct arg_formatter { using context = buffer_context; iterator out; - const basic_format_specs& specs; + const format_specs& specs; locale_ref locale; template @@ -3604,7 +3598,7 @@ template class specs_handler : public specs_setter { using format_arg = basic_format_arg>; public: - FMT_CONSTEXPR specs_handler(basic_format_specs& specs, + FMT_CONSTEXPR specs_handler(format_specs& specs, basic_format_parse_context& parse_ctx, buffer_context& ctx) : specs_setter(specs), parse_context_(parse_ctx), context_(ctx) {} @@ -4261,7 +4255,7 @@ void vformat_to(buffer& buf, basic_string_view fmt, visit_format_arg(custom_formatter{parse_context, context}, arg); return parse_context.begin(); } - auto specs = basic_format_specs(); + auto specs = format_specs(); specs_checker> handler( specs_handler(specs, parse_context, context), arg.type()); begin = parse_format_specs(begin, end, handler); diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 70a592dc..6c587382 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -194,12 +194,10 @@ template struct get_cstring { // left alignment if it is negative. template class printf_width_handler { private: - using format_specs = basic_format_specs; - - format_specs& specs_; + format_specs& specs_; public: - explicit printf_width_handler(format_specs& specs) : specs_(specs) {} + explicit printf_width_handler(format_specs& specs) : specs_(specs) {} template ::value)> unsigned operator()(T value) { @@ -226,7 +224,6 @@ class printf_arg_formatter : public arg_formatter { private: using base = arg_formatter; using context_type = basic_printf_context; - using format_specs = basic_format_specs; context_type& context_; @@ -237,7 +234,7 @@ class printf_arg_formatter : public arg_formatter { } public: - printf_arg_formatter(OutputIt iter, format_specs& s, context_type& ctx) + printf_arg_formatter(OutputIt iter, format_specs& s, context_type& ctx) : base{iter, s, locale_ref()}, context_(ctx) {} OutputIt operator()(monostate value) { return base::operator()(value); } @@ -247,7 +244,7 @@ class printf_arg_formatter : public arg_formatter { // MSVC2013 fails to compile separate overloads for bool and Char so use // std::is_same instead. if (std::is_same::value) { - format_specs fmt_specs = this->specs; + format_specs fmt_specs = this->specs; if (fmt_specs.type != presentation_type::none && fmt_specs.type != presentation_type::chr) { return (*this)(static_cast(value)); @@ -300,8 +297,7 @@ class printf_arg_formatter : public arg_formatter { }; template -void parse_flags(basic_format_specs& specs, const Char*& it, - const Char* end) { +void parse_flags(format_specs& specs, const Char*& it, const Char* end) { for (; it != end; ++it) { switch (*it) { case '-': @@ -328,8 +324,8 @@ void parse_flags(basic_format_specs& specs, const Char*& it, } template -int parse_header(const Char*& it, const Char* end, - basic_format_specs& specs, GetArg get_arg) { +int parse_header(const Char*& it, const Char* end, format_specs& specs, + GetArg get_arg) { int arg_index = -1; Char c = *it; if (c >= '0' && c <= '9') { @@ -401,7 +397,7 @@ void vprintf(buffer& buf, basic_string_view format, out = detail::write(out, basic_string_view( start, detail::to_unsigned(it - 1 - start))); - basic_format_specs specs; + auto specs = format_specs(); specs.align = align::right; // Parse argument index, flags and width. diff --git a/include/fmt/std.h b/include/fmt/std.h index ec7abaa9..32c3e454 100644 --- a/include/fmt/std.h +++ b/include/fmt/std.h @@ -191,8 +191,7 @@ template struct formatter { FMT_CONSTEXPR auto format(const std::error_code& ec, FormatContext& ctx) const -> decltype(ctx.out()) { auto out = ctx.out(); - out = detail::write_bytes(out, ec.category().name(), - basic_format_specs()); + out = detail::write_bytes(out, ec.category().name(), format_specs()); out = detail::write(out, Char(':')); out = detail::write(out, ec.value()); return out; @@ -222,7 +221,7 @@ struct formatter< template auto format(const std::exception& ex, basic_format_context& ctx) const -> OutputIt { - basic_format_specs spec; + format_specs spec; auto out = ctx.out(); if (!with_typename_) return detail::write_bytes(out, string_view(ex.what()), spec); diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 663b877d..a48684e4 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -23,7 +23,7 @@ template using is_exotic_char = bool_constant::value>; inline auto write_loc(std::back_insert_iterator> out, - loc_value value, const basic_format_specs& specs, + loc_value value, const format_specs& specs, locale_ref loc) -> bool { #ifndef FMT_STATIC_THOUSANDS_SEPARATOR auto& numpunct = diff --git a/test/format-test.cc b/test/format-test.cc index 3a75ba56..29b71d6a 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2290,11 +2290,11 @@ class format_facet : public fmt::format_facet { }; auto do_put(fmt::appender out, fmt::loc_value val, - const fmt::format_specs&) const -> bool override; + const fmt::format_specs<>&) const -> bool override; }; auto format_facet::do_put(fmt::appender out, fmt::loc_value val, - const fmt::format_specs&) const -> bool { + const fmt::format_specs<>&) const -> bool { return val.visit(int_formatter{out}); }