Fix ambiguous instantiation with formatter in fmt/ostream.h (#830)

This commit is contained in:
Victor Zverovich 2018-08-11 09:13:54 -07:00
parent 0f04ec68a9
commit 8b9fb9fb7e
2 changed files with 12 additions and 4 deletions

View File

@ -68,9 +68,7 @@ class is_streamable {
typedef decltype(test<T>(0)) result;
public:
// 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;
static const bool value = result::value;
};
// Disable conversion to int if T has an overloaded operator<< which is a free
@ -111,7 +109,10 @@ void format_value(basic_buffer<Char> &buffer, const T &value) {
// Formats an object of type T that has an overloaded ostream operator<<.
template <typename T, typename Char>
struct formatter<T, Char,
typename std::enable_if<internal::is_streamable<T, Char>::value>::type>
typename std::enable_if<
internal::is_streamable<T, Char>::value &&
!internal::format_type<
typename buffer_context<Char>::type, T>::value>::type>
: formatter<basic_string_view<Char>, Char> {
template <typename Context>

View File

@ -191,3 +191,10 @@ TEST(FormatTest, FormatToN) {
EXPECT_EQ(buffer + 3, result.out);
EXPECT_EQ("xABx", fmt::string_view(buffer, 4));
}
#if FMT_USE_USER_DEFINED_LITERALS
TEST(FormatTest, UDL) {
using namespace fmt::literals;
EXPECT_EQ("{}"_format("test"), "test");
}
#endif