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