From 99ed2a846466377bf1548753c404805033d7d254 Mon Sep 17 00:00:00 2001 From: Walter Gray Date: Wed, 23 Dec 2020 19:35:47 -0800 Subject: [PATCH] address feedback --- include/fmt/ranges.h | 37 ++++++++----------------------------- test/ranges-test.cc | 4 ++++ 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 9459c038..91f55e0b 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -37,19 +37,13 @@ struct formatting_range : formatting_base { FMT_RANGE_OUTPUT_LENGTH_LIMIT; // output only up to N items from the // range. Char prefix = '{'; - Char delimiter = ','; Char postfix = '}'; - static FMT_CONSTEXPR_DECL const bool add_delimiter_spaces = true; - static FMT_CONSTEXPR_DECL const bool add_prepostfix_space = false; }; template struct formatting_tuple : formatting_base { Char prefix = '('; - Char delimiter = ','; Char postfix = ')'; - static FMT_CONSTEXPR_DECL const bool add_delimiter_spaces = true; - static FMT_CONSTEXPR_DECL const bool add_prepostfix_space = false; }; namespace detail { @@ -247,23 +241,15 @@ template using value_type = remove_cvref_t()))>; -template -OutputIt add_range_formatting_spaces(OutputIt out, - const Formatting& formatting) { - if (const_check(formatting.add_prepostfix_space)) { - *out++ = ' '; - } - out = detail::copy(formatting.delimiter, out); - if (const_check(formatting.add_delimiter_spaces)) { - *out++ = ' '; - } +template OutputIt write_delimiter(OutputIt out) { + *out++ = ','; + *out++ = ' '; return out; } template < typename Char, typename OutputIt, typename Arg, - FMT_ENABLE_IF(std::is_same::value || - is_like_std_string::type>::value)> + FMT_ENABLE_IF(is_like_std_string::type>::value)> OutputIt write_range_entry(OutputIt out, const Arg& v) { *out++ = '"'; out = write(out, v); @@ -282,8 +268,7 @@ OutputIt write_range_entry(OutputIt out, const Arg v) { template < typename Char, typename OutputIt, typename Arg, - FMT_ENABLE_IF(!std::is_same::value && - !is_like_std_string::type>::value && + FMT_ENABLE_IF(!is_like_std_string::type>::value && !std::is_same::value)> OutputIt write_range_entry(OutputIt out, const Arg& v) { return write(out, v); @@ -303,7 +288,7 @@ struct formatter::value>> { template struct format_each { template void operator()(const T& v) { if (i > 0) { - out = add_range_formatting_spaces(out, formatting); + out = write_delimiter(out); } out = detail::write_range_entry(out, v); @@ -328,12 +313,9 @@ struct formatter::value>> { auto format(const TupleT& values, FormatContext& ctx) -> decltype(ctx.out()) { auto out = ctx.out(); size_t i = 0; - detail::copy(formatting.prefix, out); + detail::copy(formatting.prefix, out); detail::for_each(values, format_each{formatting, i, out}); - if (formatting.add_prepostfix_space) { - *out++ = ' '; - } detail::copy(formatting.postfix, out); return ctx.out(); @@ -375,7 +357,7 @@ struct formatter< auto end = view.end(); for (; it != end; ++it) { if (i > 0) { - out = detail::add_range_formatting_spaces(out, formatting); + out = detail::write_delimiter(out); } out = detail::write_range_entry(out, *it); @@ -385,9 +367,6 @@ struct formatter< break; } } - if (formatting.add_prepostfix_space) { - *out++ = ' '; - } return detail::copy(formatting.postfix, out); } }; diff --git a/test/ranges-test.cc b/test/ranges-test.cc index c05e5fcb..9ae8b08f 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -243,6 +243,10 @@ TEST(RangesTest, Range) { const std::vector z(3u, 0); EXPECT_EQ("{0, 0, 0}", fmt::format("{}", z)); + + const char* array_of_string_literals[] = {"1234", "abcd"}; + EXPECT_EQ("{\"1234\", \"abcd\"}", + fmt::format("{}", array_of_string_literals)); } #if !FMT_MSC_VER || FMT_MSC_VER >= 1927