address feedback
This commit is contained in:
parent
06a576c9dd
commit
99ed2a8464
@ -37,19 +37,13 @@ struct formatting_range : formatting_base<Char> {
|
|||||||
FMT_RANGE_OUTPUT_LENGTH_LIMIT; // output only up to N items from the
|
FMT_RANGE_OUTPUT_LENGTH_LIMIT; // output only up to N items from the
|
||||||
// range.
|
// range.
|
||||||
Char prefix = '{';
|
Char prefix = '{';
|
||||||
Char delimiter = ',';
|
|
||||||
Char postfix = '}';
|
Char postfix = '}';
|
||||||
static FMT_CONSTEXPR_DECL const bool add_delimiter_spaces = true;
|
|
||||||
static FMT_CONSTEXPR_DECL const bool add_prepostfix_space = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char, typename Enable = void>
|
template <typename Char, typename Enable = void>
|
||||||
struct formatting_tuple : formatting_base<Char> {
|
struct formatting_tuple : formatting_base<Char> {
|
||||||
Char prefix = '(';
|
Char prefix = '(';
|
||||||
Char delimiter = ',';
|
|
||||||
Char postfix = ')';
|
Char postfix = ')';
|
||||||
static FMT_CONSTEXPR_DECL const bool add_delimiter_spaces = true;
|
|
||||||
static FMT_CONSTEXPR_DECL const bool add_prepostfix_space = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
@ -247,23 +241,15 @@ template <typename Range>
|
|||||||
using value_type =
|
using value_type =
|
||||||
remove_cvref_t<decltype(*detail::range_begin(std::declval<Range>()))>;
|
remove_cvref_t<decltype(*detail::range_begin(std::declval<Range>()))>;
|
||||||
|
|
||||||
template <typename OutputIt, typename Formatting>
|
template <typename OutputIt> OutputIt write_delimiter(OutputIt out) {
|
||||||
OutputIt add_range_formatting_spaces(OutputIt out,
|
*out++ = ',';
|
||||||
const Formatting& formatting) {
|
*out++ = ' ';
|
||||||
if (const_check(formatting.add_prepostfix_space)) {
|
|
||||||
*out++ = ' ';
|
|
||||||
}
|
|
||||||
out = detail::copy(formatting.delimiter, out);
|
|
||||||
if (const_check(formatting.add_delimiter_spaces)) {
|
|
||||||
*out++ = ' ';
|
|
||||||
}
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <
|
template <
|
||||||
typename Char, typename OutputIt, typename Arg,
|
typename Char, typename OutputIt, typename Arg,
|
||||||
FMT_ENABLE_IF(std::is_same<Arg, const char*>::value ||
|
FMT_ENABLE_IF(is_like_std_string<typename std::decay<Arg>::type>::value)>
|
||||||
is_like_std_string<typename std::decay<Arg>::type>::value)>
|
|
||||||
OutputIt write_range_entry(OutputIt out, const Arg& v) {
|
OutputIt write_range_entry(OutputIt out, const Arg& v) {
|
||||||
*out++ = '"';
|
*out++ = '"';
|
||||||
out = write<Char>(out, v);
|
out = write<Char>(out, v);
|
||||||
@ -282,8 +268,7 @@ OutputIt write_range_entry(OutputIt out, const Arg v) {
|
|||||||
|
|
||||||
template <
|
template <
|
||||||
typename Char, typename OutputIt, typename Arg,
|
typename Char, typename OutputIt, typename Arg,
|
||||||
FMT_ENABLE_IF(!std::is_same<Arg, const char*>::value &&
|
FMT_ENABLE_IF(!is_like_std_string<typename std::decay<Arg>::type>::value &&
|
||||||
!is_like_std_string<typename std::decay<Arg>::type>::value &&
|
|
||||||
!std::is_same<Arg, Char>::value)>
|
!std::is_same<Arg, Char>::value)>
|
||||||
OutputIt write_range_entry(OutputIt out, const Arg& v) {
|
OutputIt write_range_entry(OutputIt out, const Arg& v) {
|
||||||
return write<Char>(out, v);
|
return write<Char>(out, v);
|
||||||
@ -303,7 +288,7 @@ struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
|
|||||||
template <typename FormatContext> struct format_each {
|
template <typename FormatContext> struct format_each {
|
||||||
template <typename T> void operator()(const T& v) {
|
template <typename T> void operator()(const T& v) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
out = add_range_formatting_spaces(out, formatting);
|
out = write_delimiter(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
out = detail::write_range_entry<Char>(out, v);
|
out = detail::write_range_entry<Char>(out, v);
|
||||||
@ -328,12 +313,9 @@ struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
|
|||||||
auto format(const TupleT& values, FormatContext& ctx) -> decltype(ctx.out()) {
|
auto format(const TupleT& values, FormatContext& ctx) -> decltype(ctx.out()) {
|
||||||
auto out = ctx.out();
|
auto out = ctx.out();
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
detail::copy(formatting.prefix, out);
|
|
||||||
|
|
||||||
|
detail::copy(formatting.prefix, out);
|
||||||
detail::for_each(values, format_each<FormatContext>{formatting, i, out});
|
detail::for_each(values, format_each<FormatContext>{formatting, i, out});
|
||||||
if (formatting.add_prepostfix_space) {
|
|
||||||
*out++ = ' ';
|
|
||||||
}
|
|
||||||
detail::copy(formatting.postfix, out);
|
detail::copy(formatting.postfix, out);
|
||||||
|
|
||||||
return ctx.out();
|
return ctx.out();
|
||||||
@ -375,7 +357,7 @@ struct formatter<
|
|||||||
auto end = view.end();
|
auto end = view.end();
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
out = detail::add_range_formatting_spaces(out, formatting);
|
out = detail::write_delimiter(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
out = detail::write_range_entry<Char>(out, *it);
|
out = detail::write_range_entry<Char>(out, *it);
|
||||||
@ -385,9 +367,6 @@ struct formatter<
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (formatting.add_prepostfix_space) {
|
|
||||||
*out++ = ' ';
|
|
||||||
}
|
|
||||||
return detail::copy(formatting.postfix, out);
|
return detail::copy(formatting.postfix, out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -243,6 +243,10 @@ TEST(RangesTest, Range) {
|
|||||||
|
|
||||||
const std::vector<int> z(3u, 0);
|
const std::vector<int> z(3u, 0);
|
||||||
EXPECT_EQ("{0, 0, 0}", fmt::format("{}", z));
|
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
|
#if !FMT_MSC_VER || FMT_MSC_VER >= 1927
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user