forked from fmtlib/fmt
Make specifiers support in tuple_join an opt-in
This commit is contained in:
@ -625,6 +625,13 @@ template <typename Char, typename... T> struct tuple_join_view : detail::view {
|
|||||||
template <typename Char, typename... T>
|
template <typename Char, typename... T>
|
||||||
using tuple_arg_join = tuple_join_view<Char, T...>;
|
using tuple_arg_join = tuple_join_view<Char, T...>;
|
||||||
|
|
||||||
|
// 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 <typename Char, typename... T>
|
template <typename Char, typename... T>
|
||||||
struct formatter<tuple_join_view<Char, T...>, Char> {
|
struct formatter<tuple_join_view<Char, T...>, Char> {
|
||||||
template <typename ParseContext>
|
template <typename ParseContext>
|
||||||
@ -654,11 +661,13 @@ struct formatter<tuple_join_view<Char, T...>, Char> {
|
|||||||
std::integral_constant<size_t, N>)
|
std::integral_constant<size_t, N>)
|
||||||
-> decltype(ctx.begin()) {
|
-> decltype(ctx.begin()) {
|
||||||
auto end = std::get<sizeof...(T) - N>(formatters_).parse(ctx);
|
auto end = std::get<sizeof...(T) - N>(formatters_).parse(ctx);
|
||||||
|
#if FMT_TUPLE_JOIN_SPECIFIERS
|
||||||
if (N > 1) {
|
if (N > 1) {
|
||||||
auto end1 = do_parse(ctx, std::integral_constant<size_t, N - 1>());
|
auto end1 = do_parse(ctx, std::integral_constant<size_t, N - 1>());
|
||||||
if (end != end1)
|
if (end != end1)
|
||||||
FMT_THROW(format_error("incompatible format specs for tuple elements"));
|
FMT_THROW(format_error("incompatible format specs for tuple elements"));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +225,7 @@ TEST(ranges_test, join_tuple) {
|
|||||||
auto t4 = std::tuple<float>(4.0f);
|
auto t4 = std::tuple<float>(4.0f);
|
||||||
EXPECT_EQ(fmt::format("{}", fmt::join(t4, "/")), "4");
|
EXPECT_EQ(fmt::format("{}", fmt::join(t4, "/")), "4");
|
||||||
|
|
||||||
|
# if FMT_TUPLE_JOIN_SPECIFIERS
|
||||||
// Specs applied to each element.
|
// Specs applied to each element.
|
||||||
auto t5 = std::tuple<int, int, long>(-3, 100, 1);
|
auto t5 = std::tuple<int, int, long>(-3, 100, 1);
|
||||||
EXPECT_EQ(fmt::format("{:+03}", fmt::join(t5, ", ")), "-03, +100, +01");
|
EXPECT_EQ(fmt::format("{:+03}", fmt::join(t5, ", ")), "-03, +100, +01");
|
||||||
@ -237,6 +238,7 @@ TEST(ranges_test, join_tuple) {
|
|||||||
int y = -1;
|
int y = -1;
|
||||||
auto t7 = std::tuple<int, int&, const int&>(3, y, y);
|
auto t7 = std::tuple<int, int&, const int&>(3, y, y);
|
||||||
EXPECT_EQ(fmt::format("{:03}", fmt::join(t7, ", ")), "003, -01, -01");
|
EXPECT_EQ(fmt::format("{:03}", fmt::join(t7, ", ")), "003, -01, -01");
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ranges_test, join_initializer_list) {
|
TEST(ranges_test, join_initializer_list) {
|
||||||
|
Reference in New Issue
Block a user