From a57f196cad3319833c1178c0aaa2bf979db64f4c Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 31 Aug 2025 16:00:59 -0700 Subject: [PATCH] Apply coding conventions --- include/fmt/base.h | 14 ++--- include/fmt/compile.h | 128 +++++++++++++++++++++--------------------- include/fmt/printf.h | 7 +-- 3 files changed, 74 insertions(+), 75 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 98129330..ecd7a855 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -1071,11 +1071,11 @@ template constexpr auto count() -> int { return (B1 ? 1 : 0) + count(); } -template constexpr auto count_named_args() -> int { - return count::value...>(); +template constexpr auto count_named_args() -> int { + return count::value...>(); } -template constexpr auto count_static_named_args() -> int { - return count::value...>(); +template constexpr auto count_static_named_args() -> int { + return count::value...>(); } template struct named_arg_info { @@ -2328,10 +2328,10 @@ template constexpr auto encode_types() -> unsigned long long { return 0; } -template +template constexpr auto encode_types() -> unsigned long long { - return static_cast(stored_type_constant::value) | - (encode_types() << packed_arg_bits); + return static_cast(stored_type_constant::value) | + (encode_types() << packed_arg_bits); } template diff --git a/include/fmt/compile.h b/include/fmt/compile.h index af787718..77d9c907 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -47,7 +47,7 @@ constexpr auto first(const T& value, const Tail&...) -> const T& { } #if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) -template struct type_list {}; +template struct type_list {}; // Returns a reference to the argument at index N from [first, rest...]. template @@ -84,8 +84,8 @@ FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view name) -> int { } template -constexpr int get_arg_index_by_name(basic_string_view name, - type_list) { +constexpr auto get_arg_index_by_name(basic_string_view name, + type_list) -> int { return get_arg_index_by_name(name); } @@ -105,8 +105,8 @@ template struct text { basic_string_view data; using char_type = Char; - template - constexpr OutputIt format(OutputIt out, const Args&...) const { + template + constexpr auto format(OutputIt out, const T&...) const -> OutputIt { return write(out, data); } }; @@ -115,8 +115,8 @@ template struct is_compiled_format> : std::true_type {}; template -constexpr text make_text(basic_string_view s, size_t pos, - size_t size) { +constexpr auto make_text(basic_string_view s, size_t pos, size_t size) + -> text { return {{&s[pos], size}}; } @@ -124,8 +124,8 @@ template struct code_unit { Char value; using char_type = Char; - template - constexpr OutputIt format(OutputIt out, const Args&...) const { + template + constexpr auto format(OutputIt out, const T&...) const -> OutputIt { *out++ = value; return out; } @@ -133,7 +133,7 @@ template struct code_unit { // This ensures that the argument type is convertible to `const T&`. template -constexpr const T& get_arg_checked(const Args&... args) { +constexpr auto get_arg_checked(const Args&... args) -> const T& { const auto& arg = detail::get(args...); if constexpr (detail::is_named_arg>()) { return arg.value; @@ -146,13 +146,13 @@ template struct is_compiled_format> : std::true_type {}; // A replacement field that refers to argument N. -template struct field { +template struct field { using char_type = Char; - template - constexpr OutputIt format(OutputIt out, const Args&... args) const { - const T& arg = get_arg_checked(args...); - if constexpr (std::is_convertible>::value) { + template + constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { + const V& arg = get_arg_checked(args...); + if constexpr (std::is_convertible>::value) { auto s = basic_string_view(arg); return copy(s.begin(), s.end(), out); } else { @@ -170,10 +170,10 @@ template struct runtime_named_field { basic_string_view name; template - constexpr static bool try_format_argument( + constexpr static auto try_format_argument( OutputIt& out, // [[maybe_unused]] due to unused-but-set-parameter warning in GCC 7,8,9 - [[maybe_unused]] basic_string_view arg_name, const T& arg) { + [[maybe_unused]] basic_string_view arg_name, const T& arg) -> bool { if constexpr (is_named_arg::type>::value) { if (arg_name == arg.name) { out = write(out, arg.value); @@ -183,8 +183,8 @@ template struct runtime_named_field { return false; } - template - constexpr OutputIt format(OutputIt out, const Args&... args) const { + template + constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { bool found = (try_format_argument(out, name, args) || ...); if (!found) { FMT_THROW(format_error("argument with specified name is not found")); @@ -197,17 +197,17 @@ template struct is_compiled_format> : std::true_type {}; // A replacement field that refers to argument N and has format specifiers. -template struct spec_field { +template struct spec_field { using char_type = Char; - formatter fmt; + formatter fmt; - template - constexpr FMT_INLINE OutputIt format(OutputIt out, - const Args&... args) const { + template + constexpr FMT_INLINE auto format(OutputIt out, const T&... args) const + -> OutputIt { const auto& vargs = fmt::make_format_args>(args...); basic_format_context ctx(out, vargs); - return fmt.format(get_arg_checked(args...), ctx); + return fmt.format(get_arg_checked(args...), ctx); } }; @@ -219,8 +219,8 @@ template struct concat { R rhs; using char_type = typename L::char_type; - template - constexpr OutputIt format(OutputIt out, const Args&... args) const { + template + constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { out = lhs.format(out, args...); return rhs.format(out, args...); } @@ -230,14 +230,14 @@ template struct is_compiled_format> : std::true_type {}; template -constexpr concat make_concat(L lhs, R rhs) { +constexpr auto make_concat(L lhs, R rhs) -> concat { return {lhs, rhs}; } struct unknown_format {}; template -constexpr size_t parse_text(basic_string_view str, size_t pos) { +constexpr auto parse_text(basic_string_view str, size_t pos) -> size_t { for (size_t size = str.size(); pos != size; ++pos) { if (str[pos] == '{' || str[pos] == '}') break; } @@ -270,8 +270,8 @@ template struct parse_specs_result { enum { manual_indexing_id = -1 }; template -constexpr parse_specs_result parse_specs(basic_string_view str, - size_t pos, int next_arg_id) { +constexpr auto parse_specs(basic_string_view str, size_t pos, + int next_arg_id) -> parse_specs_result { str.remove_prefix(pos); auto ctx = compile_parse_context(str, max_value(), nullptr, next_arg_id); @@ -285,16 +285,16 @@ template struct arg_id_handler { arg_id_kind kind; arg_ref arg_id; - constexpr int on_auto() { + constexpr auto on_auto() -> int { FMT_ASSERT(false, "handler cannot be used with automatic indexing"); return 0; } - constexpr int on_index(int id) { + constexpr auto on_index(int id) -> int { kind = arg_id_kind::index; arg_id = arg_ref(id); return 0; } - constexpr int on_name(basic_string_view id) { + constexpr auto on_name(basic_string_view id) -> int { kind = arg_id_kind::name; arg_id = arg_ref(id); return 0; @@ -433,27 +433,28 @@ FMT_BEGIN_EXPORT #if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) -template ::value)> -FMT_INLINE FMT_CONSTEXPR_STRING std::basic_string format( - const CompiledFormat& cf, const Args&... args) { +FMT_INLINE FMT_CONSTEXPR_STRING auto format(const CompiledFormat& cf, + const T&... args) + -> std::basic_string { auto s = std::basic_string(); cf.format(std::back_inserter(s), args...); return s; } -template ::value)> -constexpr FMT_INLINE OutputIt format_to(OutputIt out, const CompiledFormat& cf, - const Args&... args) { +constexpr FMT_INLINE auto format_to(OutputIt out, const CompiledFormat& cf, + const T&... args) -> OutputIt { return cf.format(out, args...); } -template ::value)> -FMT_INLINE FMT_CONSTEXPR_STRING std::basic_string format( - const S&, Args&&... args) { +FMT_INLINE FMT_CONSTEXPR_STRING auto format(const S&, T&&... args) + -> std::basic_string { if constexpr (std::is_same::value) { constexpr auto str = basic_string_view(S()); if constexpr (str.size() == 2 && str[0] == '{' && str[1] == '}') { @@ -466,63 +467,62 @@ FMT_INLINE FMT_CONSTEXPR_STRING std::basic_string format( } } } - constexpr auto compiled = detail::compile(S()); + constexpr auto compiled = detail::compile(S()); if constexpr (std::is_same, detail::unknown_format>()) { return fmt::format( static_cast>(S()), - std::forward(args)...); + std::forward(args)...); } else { - return fmt::format(compiled, std::forward(args)...); + return fmt::format(compiled, std::forward(args)...); } } -template ::value)> -FMT_CONSTEXPR OutputIt format_to(OutputIt out, const S&, Args&&... args) { - constexpr auto compiled = detail::compile(S()); +FMT_CONSTEXPR auto format_to(OutputIt out, const S&, T&&... args) -> OutputIt { + constexpr auto compiled = detail::compile(S()); if constexpr (std::is_same, detail::unknown_format>()) { return fmt::format_to( out, static_cast>(S()), - std::forward(args)...); + std::forward(args)...); } else { - return fmt::format_to(out, compiled, std::forward(args)...); + return fmt::format_to(out, compiled, std::forward(args)...); } } #endif -template ::value)> -auto format_to_n(OutputIt out, size_t n, const S& fmt, Args&&... args) +auto format_to_n(OutputIt out, size_t n, const S& fmt, T&&... args) -> format_to_n_result { using traits = detail::fixed_buffer_traits; auto buf = detail::iterator_buffer(out, n); - fmt::format_to(std::back_inserter(buf), fmt, std::forward(args)...); + fmt::format_to(std::back_inserter(buf), fmt, std::forward(args)...); return {buf.out(), buf.count()}; } -template ::value)> -FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args) - -> size_t { +FMT_CONSTEXPR20 auto formatted_size(const S& fmt, T&&... args) -> size_t { auto buf = detail::counting_buffer<>(); - fmt::format_to(appender(buf), fmt, args...); + fmt::format_to(appender(buf), fmt, std::forward(args)...); return buf.count(); } -template ::value)> -void print(std::FILE* f, const S& fmt, const Args&... args) { +void print(std::FILE* f, const S& fmt, T&&... args) { auto buf = memory_buffer(); - fmt::format_to(appender(buf), fmt, args...); + fmt::format_to(appender(buf), fmt, std::forward(args)...); detail::print(f, {buf.data(), buf.size()}); } -template ::value)> -void print(const S& fmt, const Args&... args) { - print(stdout, fmt, args...); +void print(const S& fmt, T&&... args) { + print(stdout, fmt, std::forward(args)...); } #if FMT_USE_NONTYPE_TEMPLATE_ARGS diff --git a/include/fmt/printf.h b/include/fmt/printf.h index ca184739..cd6a99b2 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -9,7 +9,7 @@ #define FMT_PRINTF_H_ #ifndef FMT_MODULE -# include // std::max +# include // std::find # include // std::numeric_limits #endif @@ -76,8 +76,7 @@ inline auto find(const char* first, const char* last, char value, // signed and unsigned integers. template struct int_checker { template static auto fits_in_int(T value) -> bool { - unsigned max = to_unsigned(max_value()); - return value <= max; + return value <= to_unsigned(max_value()); } inline static auto fits_in_int(bool) -> bool { return true; } }; @@ -95,7 +94,7 @@ struct printf_precision_handler { auto operator()(T value) -> int { if (!int_checker::is_signed>::fits_in_int(value)) report_error("number is too big"); - return (std::max)(static_cast(value), 0); + return max_of(static_cast(value), 0); } template ::value)>