mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +00:00
Fix a conflict between fmt::join and fmt/ostream.h (#744)
This commit is contained in:
parent
6ebc1a967d
commit
5ad54256c5
@ -53,10 +53,10 @@ struct test_stream : std::basic_ostream<Char> {
|
|||||||
void operator<<(null);
|
void operator<<(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Disable conversion to int if T has an overloaded operator<< which is a free
|
// Checks if T has an overloaded operator<< which is a free function (not a
|
||||||
// function (not a member of std::ostream).
|
// member of std::ostream).
|
||||||
template <typename T, typename Char>
|
template <typename T, typename Char>
|
||||||
class convert_to_int<T, Char, true> {
|
class is_streamable {
|
||||||
private:
|
private:
|
||||||
template <typename U>
|
template <typename U>
|
||||||
static decltype(
|
static decltype(
|
||||||
@ -69,7 +69,16 @@ class convert_to_int<T, Char, true> {
|
|||||||
typedef decltype(test<T>(0)) result;
|
typedef decltype(test<T>(0)) result;
|
||||||
|
|
||||||
public:
|
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 <typename T, typename Char>
|
||||||
|
class convert_to_int<T, Char, true> {
|
||||||
|
public:
|
||||||
|
static const bool value =
|
||||||
|
convert_to_int<T, Char, false>::value && !is_streamable<T, Char>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Write the content of buf to os.
|
// Write the content of buf to os.
|
||||||
@ -106,8 +115,7 @@ struct format_enum<T,
|
|||||||
// Formats an object of type T that has an overloaded ostream operator<<.
|
// Formats an object of type T that has an overloaded ostream operator<<.
|
||||||
template <typename T, typename Char>
|
template <typename T, typename Char>
|
||||||
struct formatter<T, Char,
|
struct formatter<T, Char,
|
||||||
typename std::enable_if<!internal::format_type<
|
typename std::enable_if<internal::is_streamable<T, Char>::value>::type>
|
||||||
typename buffer_context<Char>::type, T>::value>::type>
|
|
||||||
: formatter<basic_string_view<Char>, Char> {
|
: formatter<basic_string_view<Char>, Char> {
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
|
@ -158,3 +158,8 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
|
|||||||
} while (size != 0);
|
} while (size != 0);
|
||||||
fmt::internal::write(os, buffer);
|
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, ", ")));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user