Skip to content

Commit

Permalink
Reintroduce ostream support to range formatters (#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Nov 24, 2020
1 parent b8957f5 commit 5899276
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion test/ostream-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//
// For the license information refer to format.h.

#define FMT_STRING_ALIAS 1
#include "fmt/format.h"

struct test {};
Expand All @@ -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"
Expand Down Expand Up @@ -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));
}

0 comments on commit 5899276

Please sign in to comment.