From 813ac495437857691b71d5ae6a6e19078d05a41a Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 17 May 2021 07:50:29 -0700 Subject: [PATCH] More API cleanups --- include/fmt/core.h | 26 ++++++++++++++++++++++-- include/fmt/format.h | 48 +++++++++++++------------------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index d92525e8..c74d44d2 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2834,8 +2834,6 @@ struct formatter with -// vformat_to(...) overload, so SFINAE on iterator type instead. template , bool enable = detail::is_output_iterator::value> auto vformat_to(OutputIt out, const S& format_str, @@ -2920,6 +2918,30 @@ FMT_INLINE auto vformat( return detail::vformat(to_string_view(format_str), args); } +#if FMT_COMPILE_TIME_CHECKS +template struct format_string { + string_view str; + + template consteval format_string(const char (&s)[N]) : str(s) { + if constexpr (detail::count_named_args() == 0) { + using checker = detail::format_string_checker...>; + detail::parse_format_string(string_view(s, N), checker(s, {})); + } + } + + template )> + format_string(const T& s) : str(s) {} +}; + +template +FMT_INLINE std::string format( + format_string...> format_str, Args&&... args) { + return detail::vformat(format_str.str, make_format_args(args...)); +} +#endif + /** \rst Formats arguments and returns the result as a string. diff --git a/include/fmt/format.h b/include/fmt/format.h index ca5497b9..f86afcf2 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2776,47 +2776,27 @@ inline void vformat_to( template ::value, char_t>> -inline typename buffer_context::iterator format_to( - basic_memory_buffer& buf, const S& format_str, Args&&... args) { +inline auto format_to(basic_memory_buffer& buf, const S& format_str, + Args&&... args) -> + typename buffer_context::iterator { const auto& vargs = fmt::make_args_checked(format_str, args...); detail::vformat_to(buf, to_string_view(format_str), vargs); return detail::buffer_appender(buf); } template -using format_context_t = basic_format_context; +using format_context_t FMT_DEPRECATED_ALIAS = + basic_format_context; template -using format_args_t = basic_format_args>; - -#if FMT_COMPILE_TIME_CHECKS -template struct format_string { - string_view str; - - template consteval format_string(const char (&s)[N]) : str(s) { - if constexpr (detail::count_named_args() == 0) { - using checker = detail::format_string_checker...>; - detail::parse_format_string(string_view(s, N), checker(s, {})); - } - } - - template )> - format_string(const T& s) : str(s) {} -}; - -template -FMT_INLINE std::string format( - format_string...> format_str, Args&&... args) { - return detail::vformat(format_str.str, make_format_args(args...)); -} -#endif +using format_args_t FMT_DEPRECATED_ALIAS = + basic_format_args>; template ::value), int>> -std::basic_string detail::vformat( +auto detail::vformat( basic_string_view format_str, - basic_format_args>> args) { + basic_format_args>> args) + -> std::basic_string { basic_memory_buffer buffer; detail::vformat_to(buffer, format_str, args); return to_string(buffer); @@ -2906,12 +2886,12 @@ inline namespace literals { std::string message = "The answer is {}"_format(42); \endrst */ -constexpr detail::udl_formatter operator"" _format(const char* s, - size_t n) { +constexpr auto operator"" _format(const char* s, size_t n) + -> detail::udl_formatter { return {{s, n}}; } -constexpr detail::udl_formatter operator"" _format(const wchar_t* s, - size_t n) { +constexpr auto operator"" _format(const wchar_t* s, size_t n) + -> detail::udl_formatter { return {{s, n}}; }