-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!formatC++20/23 formatC++20/23 format
Description
Underlying formatters of pair-or-tuple formatter should be able to call format_ctx.arg(I) and get correct format arg.
Example:
#include <print>
#include <thread>
template <size_t I> struct substitute_arg {};
template <size_t I> struct std::formatter<substitute_arg<I>> {
template <class ParseContext> constexpr auto parse(ParseContext &ctx) {
auto it = ctx.begin();
if (it != ctx.end() && *it != '}') {
throw format_error{"Expected empty spec"};
}
ctx.check_arg_id(I);
return it;
}
template <class FormatContext>
auto format(substitute_arg<I>, FormatContext &ctx) const {
auto visitor = [&]<class T>(T val) -> FormatContext::iterator {
if constexpr (same_as<T, monostate>) {
return ranges::copy("monostate"sv, ctx.out()).out;
} else if constexpr (same_as<T, typename basic_format_arg<
FormatContext>::handle>) {
format_parse_context parse_ctx{""};
val.format(parse_ctx, ctx);
return ctx.out();
} else {
return format_to(ctx.out(), "{}", val);
}
};
return visit_format_arg(visitor, ctx.arg(I));
}
};
int main() {
std::println("{0:}", std::tuple{substitute_arg<1>{}, substitute_arg<2>{}},
"thread::id", std::thread::id{});
}Expected output (libc++: https://godbolt.org/z/1c4fdhzTb):
(thread::id, 0)We've got:
(monostate, monostate)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!formatC++20/23 formatC++20/23 format