From 258194623141a3f4293a70b4388d52362cafc93a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 16 May 2021 12:48:20 -0700 Subject: [PATCH] Cleanup the core API --- include/fmt/core.h | 66 ++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 9fe1a939..d92525e8 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2135,9 +2135,9 @@ FMT_CONSTEXPR const Char* do_parse_arg_id(const Char* begin, const Char* end, } template -FMT_CONSTEXPR_DECL FMT_INLINE const Char* parse_arg_id(const Char* begin, - const Char* end, - IDHandler&& handler) { +FMT_CONSTEXPR FMT_INLINE const Char* parse_arg_id(const Char* begin, + const Char* end, + IDHandler&& handler) { Char c = *begin; if (c != '}' && c != ':') return do_parse_arg_id(begin, end, handler); handler(); @@ -2220,8 +2220,9 @@ FMT_CONSTEXPR const Char* parse_precision(const Char* begin, const Char* end, // Parses standard format specifiers and sends notifications about parsed // components to handler. template -FMT_CONSTEXPR_DECL FMT_INLINE const Char* parse_format_specs( - const Char* begin, const Char* end, SpecHandler&& handler) { +FMT_CONSTEXPR FMT_INLINE const Char* parse_format_specs(const Char* begin, + const Char* end, + SpecHandler&& handler) { if (begin + 1 < end && begin[1] == '}' && is_ascii_letter(*begin) && *begin != 'L') { handler.on_type(*begin++); @@ -2324,7 +2325,7 @@ FMT_CONSTEXPR const Char* parse_replacement_field(const Char* begin, } template -FMT_CONSTEXPR_DECL FMT_INLINE void parse_format_string( +FMT_CONSTEXPR FMT_INLINE void parse_format_string( basic_string_view format_str, Handler&& handler) { // this is most likely a name-lookup defect in msvc's modules implementation using detail::find; @@ -2525,8 +2526,7 @@ FMT_CONSTEXPR float_specs parse_float_type_spec( template class cstring_type_checker : public ErrorHandler { public: - FMT_CONSTEXPR explicit cstring_type_checker(ErrorHandler eh) - : ErrorHandler(eh) {} + constexpr explicit cstring_type_checker(ErrorHandler eh) : ErrorHandler(eh) {} FMT_CONSTEXPR void on_string() {} FMT_CONSTEXPR void on_pointer() {} @@ -2678,10 +2678,10 @@ class format_string_checker { template ::value), int>> void check_format_string(S format_str) { - FMT_CONSTEXPR_DECL auto s = to_string_view(format_str); + FMT_CONSTEXPR auto s = to_string_view(format_str); using checker = format_string_checker...>; - FMT_CONSTEXPR_DECL bool invalid_format = + FMT_CONSTEXPR bool invalid_format = (parse_format_string(s, checker(s, {})), true); (void)invalid_format; } @@ -2727,11 +2727,11 @@ constexpr auto compile_string_to_view(std_string_view s) #define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::compile_string) template ::value)> -std::basic_string vformat( - basic_string_view format_str, - basic_format_args>> args); +auto vformat(basic_string_view format_str, + basic_format_args>> args) + -> std::basic_string; -FMT_API std::string vformat(string_view format_str, format_args args); +FMT_API auto vformat(string_view format_str, format_args args) -> std::string; template void vformat_to( @@ -2769,9 +2769,9 @@ struct formatter; auto type = detail::type_constant::value; - detail::specs_checker handler(handler_type(specs_, ctx), - type); - auto it = detail::parse_format_specs(begin, end, handler); + auto checker = + detail::specs_checker(handler_type(specs_, ctx), type); + auto it = detail::parse_format_specs(begin, end, checker); auto eh = ctx.error_handler(); switch (type) { case detail::type::none_type: @@ -2821,7 +2821,7 @@ struct formatter, bool enable = detail::is_output_iterator::value> auto vformat_to(OutputIt out, const S& format_str, basic_format_args>> args) - -> typename std::enable_if::type { + -> enable_if_t { decltype(detail::get_buffer(out)) buf(detail::get_buffer_init(out)); detail::vformat_to(buf, to_string_view(format_str), args); return detail::get_iterator(buf); @@ -2859,9 +2859,9 @@ auto vformat_to(OutputIt out, const S& format_str, */ // We cannot use FMT_ENABLE_IF because of a bug in gcc 8.3. template >::value> -inline auto format_to(OutputIt out, const S& format_str, Args&&... args) -> - typename std::enable_if::type { + FMT_ENABLE_IF(detail::is_output_iterator>::value)> +inline auto format_to(OutputIt out, const S& format_str, Args&&... args) + -> OutputIt { const auto& vargs = fmt::make_args_checked(format_str, args...); return vformat_to(out, to_string_view(format_str), vargs); } @@ -2875,9 +2875,10 @@ template struct format_to_n_result { template ::value)> -inline format_to_n_result vformat_to_n( +inline auto vformat_to_n( OutputIt out, size_t n, basic_string_view format_str, - basic_format_args>> args) { + basic_format_args>> args) + -> format_to_n_result { detail::iterator_buffer buf(out, n); detail::vformat_to(buf, format_str, args); @@ -2892,10 +2893,9 @@ inline format_to_n_result vformat_to_n( \endrst */ template >::value> + FMT_ENABLE_IF(detail::is_output_iterator>::value)> inline auto format_to_n(OutputIt out, size_t n, const S& format_str, - const Args&... args) -> - typename std::enable_if>::type { + const Args&... args) -> format_to_n_result { const auto& vargs = fmt::make_args_checked(format_str, args...); return vformat_to_n(out, n, to_string_view(format_str), vargs); } @@ -2905,17 +2905,18 @@ inline auto format_to_n(OutputIt out, size_t n, const S& format_str, ``format(format_str, args...)``. */ template > -inline size_t formatted_size(const S& format_str, Args&&... args) { - const auto& vargs = fmt::make_args_checked(format_str, args...); +inline auto formatted_size(const S& format_str, Args&&... args) -> size_t { detail::counting_buffer<> buf; + const auto& vargs = fmt::make_args_checked(format_str, args...); detail::vformat_to(buf, to_string_view(format_str), vargs); return buf.count(); } template > -FMT_INLINE std::basic_string vformat( +FMT_INLINE auto vformat( const S& format_str, - basic_format_args>> args) { + basic_format_args>> args) + -> std::basic_string { return detail::vformat(to_string_view(format_str), args); } @@ -2934,7 +2935,8 @@ FMT_INLINE std::basic_string vformat( template , FMT_ENABLE_IF(!FMT_COMPILE_TIME_CHECKS || !std::is_same::value)> -FMT_INLINE std::basic_string format(const S& format_str, Args&&... args) { +FMT_INLINE auto format(const S& format_str, Args&&... args) + -> std::basic_string { const auto& vargs = fmt::make_args_checked(format_str, args...); return detail::vformat(to_string_view(format_str), vargs); }