From 98f793118d71f7f4c81c3a96878fb0e05efa51fb Mon Sep 17 00:00:00 2001 From: Matthias Moulin Date: Thu, 23 May 2024 20:10:26 +0200 Subject: [PATCH] Added range_format::string formatter Either the basic_string_view range constructor or a user-defined conversion operator will be used. --- include/fmt/ranges.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 57ccb6a0ae3d8..3b5d7d76b56bb 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -515,7 +515,8 @@ struct formatter< enable_if_t::value != range_format::disabled && - range_format_kind::value != range_format::map> + range_format_kind::value != range_format::map && + range_format_kind::value != range_format::string> // Workaround a bug in MSVC 2015 and earlier. #if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1910 , @@ -604,6 +605,28 @@ struct formatter< } }; +// A string formatter. +template +struct formatter< + R, Char, + enable_if_t::value == range_format::string>> { + private: + using range_type = detail::maybe_const_range; + formatter, Char> range_formatter_; + + public: + template + FMT_CONSTEXPR auto parse(ParseContext& ctx) -> decltype(ctx.begin()) { + return range_formatter_.parse(ctx); + } + + template + auto format(range_type& range, FormatContext& ctx) const + -> decltype(ctx.out()) { + return range_formatter_.format(detail::std_string_view(range), ctx); + } +}; + template struct join_view : detail::view { It begin;