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..afd3c0f8 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,35 @@ 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; + + using iterator = typename std::vector::iterator; + using const_iterator = typename std::vector::const_iterator; + + template + explicit flat_set(Ts&&... args) : c{std::forward(args)...} {} + + iterator begin() { return c.begin(); } + const_iterator begin() const { return c.begin(); } + + iterator end() { return c.end(); } + const_iterator end() const { 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;