diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 266b9e1b..65beba5b 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -668,8 +668,11 @@ template struct all { } // namespace detail template -struct formatter::value>> +struct formatter< + T, Char, + enable_if_t, + bool_constant::value == + range_format::disabled>>::value>> : formatter, Char> { using all = detail::all; template diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 6cd28fab..209318b7 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "gtest/gtest.h" @@ -80,6 +81,32 @@ TEST(ranges_test, format_set) { "{\"one\", \"two\"}"); } +// Models std::flat_set close enough to test if no ambiguous lookup of a +// formatter happens due to the flat_set type matching is_set and +// is_container_adaptor_like +template class flat_set { + public: + using key_type = T; + using container_type = std::vector; + + template + explicit flat_set(Ts&&... args) : c{std::forward(args)...} {} + + auto begin() -> decltype(auto) { return c.begin(); } + auto begin() const -> decltype(auto) { return c.begin(); } + + auto end() -> decltype(auto) { return c.end(); } + auto end() const -> decltype(auto) { return c.end(); } + + private: + std::vector c; +}; + +TEST(ranges_test, format_flat_set) { + EXPECT_EQ(fmt::format("{}", flat_set{"one", "two"}), + "{\"one\", \"two\"}"); +} + namespace adl { struct box { int value;