From 79981a25287d957acede2fb594e1c9c5e7fa101f Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 25 Dec 2022 19:54:48 -0800 Subject: [PATCH] Cleanup ranges formatting --- include/fmt/ranges.h | 64 ++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index fc7bdd1a..769cf809 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -22,27 +22,25 @@ FMT_BEGIN_NAMESPACE namespace detail { -template -OutputIterator copy(const RangeT& range, OutputIterator out) { +template +auto copy(const Range& range, OutputIt out) -> OutputIt { for (auto it = range.begin(), end = range.end(); it != end; ++it) *out++ = *it; return out; } -template -OutputIterator copy(const char* str, OutputIterator out) { +template +auto copy(const char* str, OutputIt out) -> OutputIt { while (*str) *out++ = *str++; return out; } -template -OutputIterator copy(char ch, OutputIterator out) { +template auto copy(char ch, OutputIt out) -> OutputIt { *out++ = ch; return out; } -template -OutputIterator copy(wchar_t ch, OutputIterator out) { +template auto copy(wchar_t ch, OutputIt out) -> OutputIt { *out++ = ch; return out; } @@ -69,7 +67,7 @@ template class is_map { template static void check(...); public: -#ifdef FMT_FORMAT_MAP_AS_LIST +#ifdef FMT_FORMAT_MAP_AS_LIST // DEPRECATED! static constexpr const bool value = false; #else static constexpr const bool value = @@ -82,7 +80,7 @@ template class is_set { template static void check(...); public: -#ifdef FMT_FORMAT_SET_AS_LIST +#ifdef FMT_FORMAT_SET_AS_LIST // DEPRECATED! static constexpr const bool value = false; #else static constexpr const bool value = @@ -230,14 +228,14 @@ template class is_tuple_formattable_ { template void for_each(index_sequence, Tuple&& tup, F&& f) noexcept { using std::get; - // using free function get(T) now. - const int _[] = {0, ((void)f(get(tup)), 0)...}; - (void)_; // blocks warnings + // Using free function get(T) now. + const int unused[] = {0, ((void)f(get(tup)), 0)...}; + (void)unused; } template -FMT_CONSTEXPR make_index_sequence::value> get_indexes( - T const&) { +FMT_CONSTEXPR auto get_indexes(T const&) + -> make_index_sequence::value> { return {}; } @@ -295,18 +293,18 @@ inline auto write_range_entry(OutputIt out, const T& str) -> OutputIt { return write_range_entry(out, basic_string_view(sv)); } -template ::value)> -OutputIt write_range_entry(OutputIt out, const Arg v) { - return write_escaped_char(out, v); +template ::value)> +auto write_range_entry(OutputIt out, T value) -> OutputIt { + return write_escaped_char(out, value); } template < - typename Char, typename OutputIt, typename Arg, - FMT_ENABLE_IF(!is_std_string_like::type>::value && - !std::is_same::value)> -OutputIt write_range_entry(OutputIt out, const Arg& v) { - return write(out, v); + typename Char, typename OutputIt, typename T, + FMT_ENABLE_IF(!is_std_string_like::type>::value && + !std::is_same::value)> +auto write_range_entry(OutputIt out, const T& value) -> OutputIt { + return write(out, value); } } // namespace detail @@ -321,10 +319,10 @@ template struct is_tuple_formattable { detail::is_tuple_formattable_::value; }; -template -struct formatter::value && - fmt::is_tuple_formattable::value>> { +template +struct formatter::value && + fmt::is_tuple_formattable::value>> { private: basic_string_view separator_ = detail::string_literal{}; basic_string_view opening_bracket_ = @@ -363,11 +361,10 @@ struct formatter - auto format(const TupleT& values, FormatContext& ctx) const + auto format(const Tuple& value, FormatContext& ctx) const -> decltype(ctx.out()) { - auto out = ctx.out(); - out = detail::copy_str(opening_bracket_, out); - detail::for_each(values, format_each{0, out, separator_}); + auto out = detail::copy_str(opening_bracket_, ctx.out()); + detail::for_each(value, format_each{0, out, separator_}); out = detail::copy_str(closing_bracket_, out); return out; } @@ -594,9 +591,6 @@ template struct tuple_join_view : detail::view { : tuple(t), sep{s} {} }; -template -using tuple_arg_join = tuple_join_view; - // Define FMT_TUPLE_JOIN_SPECIFIERS to enable experimental format specifiers // support in tuple_join. It is disabled by default because of issues with // the dynamic width and precision.