aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Zverovich <victor.zverovich@gmail.com>2020-11-21 16:31:22 -0800
committerVictor Zverovich <victor.zverovich@gmail.com>2020-11-24 08:22:29 -0800
commit58992761cfe8b6a93bf16bd8a078d3144826a866 (patch)
tree0a044fcaa9b4c77fca39e60344136c89a732643a
parentb8957f50c31d80bd0fb9420d3ec2a0d0a8838a4d (diff)
downloadfmtlib-58992761cfe8b6a93bf16bd8a078d3144826a866.tar.gz
Reintroduce ostream support to range formatters (#2014)
-rw-r--r--include/fmt/ranges.h5
-rw-r--r--test/ostream-test.cc7
2 files changed, 10 insertions, 2 deletions
diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h
index b603d637..632f0494 100644
--- a/include/fmt/ranges.h
+++ b/include/fmt/ranges.h
@@ -254,7 +254,10 @@ struct formatter<
enable_if_t<fmt::is_range<T, Char>::value
// Workaround a bug in MSVC 2017 and earlier.
#if !FMT_MSC_VER || FMT_MSC_VER >= 1927
- && has_formatter<detail::value_type<T>, format_context>::value
+ &&
+ (has_formatter<detail::value_type<T>, format_context>::value ||
+ detail::has_fallback_formatter<detail::value_type<T>,
+ format_context>::value)
#endif
>> {
formatting_range<Char> formatting;
diff --git a/test/ostream-test.cc b/test/ostream-test.cc
index ebf14210..4f432fb9 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<test> : formatter<int> {
#include <sstream>
#include "fmt/ostream.h"
+#include "fmt/ranges.h"
#include "gmock.h"
#include "gtest-extra.h"
#include "util.h"
@@ -323,3 +323,8 @@ TEST(OStreamTest, CompileTimeString) {
TEST(OStreamTest, ToString) {
EXPECT_EQ("ABC", fmt::to_string(fmt_test::ABC()));
}
+
+TEST(OStreamTest, Range) {
+ auto strs = std::vector<TestString>{TestString("foo"), TestString("bar")};
+ EXPECT_EQ("{foo, bar}", format("{}", strs));
+} \ No newline at end of file