From a036cc97b7e547ad93d031abb3b66c7c4ab70662 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 21 Nov 2020 16:31:22 -0800 Subject: [PATCH] Reintroduce ostream support to range formatters (#2014) --- include/fmt/ranges.h | 5 ++++- test/ostream-test.cc | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 63cad9ab..732d3209 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -341,7 +341,10 @@ struct formatter< enable_if_t::value // Workaround a bug in MSVC 2017 and earlier. #if !FMT_MSC_VER || FMT_MSC_VER >= 1927 - && has_formatter, format_context>::value + && + (has_formatter, format_context>::value || + detail::has_fallback_formatter, + format_context>::value) #endif >> { formatting_range formatting; diff --git a/test/ostream-test.cc b/test/ostream-test.cc index bd93a17c..9849f4c8 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -5,7 +5,6 @@ // // For the license information refer to format.h. -#define FMT_STRING_ALIAS 1 #include "fmt/format.h" struct test {}; @@ -24,6 +23,7 @@ template <> struct formatter : formatter { #include #include "fmt/ostream.h" +#include "fmt/ranges.h" #include "gmock.h" #include "gtest-extra.h" #include "util.h" @@ -324,3 +324,8 @@ TEST(OStreamTest, CompileTimeString) { TEST(OStreamTest, ToString) { EXPECT_EQ("ABC", fmt::to_string(fmt_test::ABC())); } + +TEST(OStreamTest, Range) { + auto strs = std::vector{TestString("foo"), TestString("bar")}; + EXPECT_EQ("{foo, bar}", format("{}", strs)); +} \ No newline at end of file