Fix handling of set_debug_format

This commit is contained in:
Victor Zverovich 2023-12-23 08:32:36 -08:00
parent 56d7a8c157
commit 3eb3aef575
2 changed files with 15 additions and 5 deletions

View File

@ -4097,13 +4097,10 @@ class format_int {
template <typename T, typename Char>
struct formatter<T, Char, enable_if_t<detail::has_format_as<T>::value>>
: private formatter<detail::format_as_t<T>, Char> {
using base = formatter<detail::format_as_t<T>, Char>;
using base::parse;
using base::set_debug_format;
: formatter<detail::format_as_t<T>, Char> {
template <typename FormatContext>
auto format(const T& value, FormatContext& ctx) const -> decltype(ctx.out()) {
using base = formatter<detail::format_as_t<T>, Char>;
return base::format(format_as(value), ctx);
}
};

View File

@ -528,3 +528,16 @@ TEST(ranges_test, container_adaptor) {
EXPECT_EQ(fmt::format("{}", m), "[1, 2]");
}
}
struct tieable {
int a = 3;
double b = 0.42;
};
auto format_as(const tieable& t) -> std::tuple<int, double> {
return std::tie(t.a, t.b);
}
TEST(ranges_test, format_as_tie) {
EXPECT_EQ(fmt::format("{}", tieable()), "(3, 0.42)");
}