Fix handling of compile-time strings when including ostream.h (#768)

This commit is contained in:
Victor Zverovich 2018-06-10 19:05:27 +02:00
parent e3707ef14b
commit 9ff3b6af2e
2 changed files with 8 additions and 3 deletions

View File

@ -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:
@ -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

View File

@ -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")));
}