From 2fe94ad7e3cc440b71c6dc89ec1e77c069d60872 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 5 Sep 2021 07:34:06 -0700 Subject: [PATCH] Make specifiers support in tuple_join an opt-in --- include/fmt/ranges.h | 9 +++++++++ test/ranges-test.cc | 2 ++ 2 files changed, 11 insertions(+) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index ab78a851..ee12bd95 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -625,6 +625,13 @@ template struct tuple_join_view : detail::view { 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. +#ifndef FMT_TUPLE_JOIN_SPECIFIERS +# define FMT_TUPLE_JOIN_SPECIFIERS 0 +#endif + template struct formatter, Char> { template @@ -654,11 +661,13 @@ struct formatter, Char> { std::integral_constant) -> decltype(ctx.begin()) { auto end = std::get(formatters_).parse(ctx); +#if FMT_TUPLE_JOIN_SPECIFIERS if (N > 1) { auto end1 = do_parse(ctx, std::integral_constant()); if (end != end1) FMT_THROW(format_error("incompatible format specs for tuple elements")); } +#endif return end; } diff --git a/test/ranges-test.cc b/test/ranges-test.cc index d918ad59..1c572e62 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -225,6 +225,7 @@ TEST(ranges_test, join_tuple) { auto t4 = std::tuple(4.0f); EXPECT_EQ(fmt::format("{}", fmt::join(t4, "/")), "4"); +# if FMT_TUPLE_JOIN_SPECIFIERS // Specs applied to each element. auto t5 = std::tuple(-3, 100, 1); EXPECT_EQ(fmt::format("{:+03}", fmt::join(t5, ", ")), "-03, +100, +01"); @@ -237,6 +238,7 @@ TEST(ranges_test, join_tuple) { int y = -1; auto t7 = std::tuple(3, y, y); EXPECT_EQ(fmt::format("{:03}", fmt::join(t7, ", ")), "003, -01, -01"); +# endif } TEST(ranges_test, join_initializer_list) {