mirror of
https://github.com/fmtlib/fmt.git
synced 2025-03-30 13:20:18 +00:00
Fix handling of compile-time strings when including ostream.h (#768)
This commit is contained in:
parent
e3707ef14b
commit
9ff3b6af2e
@ -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
|
||||
|
@ -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")));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user