diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index b9ec7ca4..8d44cd1e 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -353,9 +353,7 @@ template struct is_range { * */ FMT_EXPORT -template -struct is_container_adaptor : std::true_type {}; - +template struct is_container_adaptor : std::true_type {}; namespace detail { @@ -780,7 +778,7 @@ template struct formatter< T, Char, enable_if_t, - is_container_adaptor, // -> added the sanity checker + is_container_adaptor, bool_constant::value == range_format::disabled>>::value>> : formatter, Char> { diff --git a/test/ranges-test.cc b/test/ranges-test.cc index 6d5cdaa8..f2ab3c9f 100644 --- a/test/ranges-test.cc +++ b/test/ranges-test.cc @@ -5,10 +5,6 @@ // // For the license information refer to format.h. -#include "fmt/ranges.h" -#include "fmt/ranges.h" -#include "fmt/ranges.h" -#include "fmt/ranges.h" #include "fmt/ranges.h" #include @@ -21,8 +17,9 @@ #include #include -#include "posix-mock.h" #include "fmt/base.h" +#include "fmt/ranges.h" +#include "posix-mock.h" #if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE() # include @@ -805,42 +802,40 @@ struct not_range { }; static_assert(!fmt::is_formattable{}, ""); -namespace test_detail -{ - template - struct partial_opt_out_wrapper - { - using container_type = std::vector; - std::vector c = {1, 2, 3}; - auto begin() const {return c.begin(); } - auto end() const {return c.end(); } +namespace test_detail { +template struct partial_opt_out_wrapper { + using container_type = std::vector; + std::vector c = {1, 2, 3}; - }; + typename std::vector::const_iterator begin() const { return c.begin(); } + typename std::vector::const_iterator end() const { return c.end(); } +}; +} // namespace test_detail -} -namespace fmt -{ - // disables is_range - template - struct fmt::is_range, char> : std::false_type{}; - // opt-out of the container adaptor format - template - struct fmt::is_container_adaptor> : std::false_type{}; -} -//a custom partial specializtion +namespace fmt { template -struct fmt::formatter> -{ - constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); } - auto format(const test_detail::partial_opt_out_wrapper& val, fmt::format_context& ctx) const +struct is_range, char> + : std::false_type {}; + +template +struct is_container_adaptor> + : std::false_type {}; +} // namespace fmt + +template +struct fmt::formatter> { + fmt::format_parse_context::iterator parse(fmt::format_parse_context& ctx) { - return fmt::format_to(ctx.out(), "PartialOptOut(size={})", val.c.size()); + return ctx.begin(); } + fmt::format_context::iterator format(const test_detail::partial_opt_out_wrapper& val, + fmt::format_context& ctx) const { + return fmt::format_to(ctx.out(), "PartialOptOut(size={})", val.c.size()); + } }; -TEST(ranges_test, container_adaptor_partial_specialization) -{ + +TEST(ranges_test, container_adaptor_partial_specialization) { test_detail::partial_opt_out_wrapper obj; EXPECT_EQ(fmt::format("{}", obj), "PartialOptOut(size=3)"); -} - +} \ No newline at end of file