Skip to content

Commit

Permalink
Fix handling of compile-time strings when including ostream.h (#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jun 10, 2018
1 parent e3707ef commit 9ff3b6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/fmt/ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ struct test_stream : std::basic_ostream<Char> {
void operator<<(null);
};

// Checks if T has an overloaded operator<< which is a free function (not a
// member of std::ostream).
// Checks if T has a user-defined operator<< (e.g. not a member of std::ostream).
template <typename T, typename Char>
class is_streamable {
private:
Expand All @@ -69,7 +68,9 @@ class is_streamable {
typedef decltype(test<T>(0)) result;

public:
static const bool value = result::value;
// std::string operator<< is not considered user-defined because we handle strings
// specially.
static const bool value = result::value && !std::is_same<T, std::string>::value;
};

// Disable conversion to int if T has an overloaded operator<< which is a free
Expand Down
4 changes: 4 additions & 0 deletions test/ostream-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,7 @@ TEST(OStreamTest, Join) {
int v[3] = {1, 2, 3};
EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join(v, v + 3, ", ")));
}

TEST(OStreamTest, ConstexprString) {
EXPECT_EQ("42", format(fmt("{}"), std::string("42")));
}

0 comments on commit 9ff3b6a

Please sign in to comment.