diff --git a/include/fmt/ostream.h b/include/fmt/ostream.h index 5daa272b..cdb39047 100644 --- a/include/fmt/ostream.h +++ b/include/fmt/ostream.h @@ -53,10 +53,10 @@ struct test_stream : std::basic_ostream { void operator<<(null); }; -// Disable conversion to int if T has an overloaded operator<< which is a free -// function (not a member of std::ostream). +// Checks if T has an overloaded operator<< which is a free function (not a +// member of std::ostream). template -class convert_to_int { +class is_streamable { private: template static decltype( @@ -69,7 +69,16 @@ class convert_to_int { typedef decltype(test(0)) result; public: - static const bool value = !result::value; + static const bool value = result::value; +}; + +// Disable conversion to int if T has an overloaded operator<< which is a free +// function (not a member of std::ostream). +template +class convert_to_int { + public: + static const bool value = + convert_to_int::value && !is_streamable::value; }; // Write the content of buf to os. @@ -106,8 +115,7 @@ struct format_enum struct formatter::type, T>::value>::type> + typename std::enable_if::value>::type> : formatter, Char> { template diff --git a/test/ostream-test.cc b/test/ostream-test.cc index bdb81651..ffc2f8b2 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -158,3 +158,8 @@ TEST(OStreamTest, WriteToOStreamMaxSize) { } while (size != 0); fmt::internal::write(os, buffer); } + +TEST(OStreamTest, Join) { + int v[3] = {1, 2, 3}; + EXPECT_EQ("1, 2, 3", fmt::format("{}", fmt::join(v, v + 3, ", "))); +}