mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Don't use const char* overload of operator<< (#1309)
This commit is contained in:
@ -46,9 +46,9 @@ template <class Char> class formatbuf : public std::basic_streambuf<Char> {
|
|||||||
|
|
||||||
template <typename Char> struct test_stream : std::basic_ostream<Char> {
|
template <typename Char> struct test_stream : std::basic_ostream<Char> {
|
||||||
private:
|
private:
|
||||||
struct null;
|
|
||||||
// Hide all operator<< from std::basic_ostream<Char>.
|
// Hide all operator<< from std::basic_ostream<Char>.
|
||||||
void operator<<(null);
|
void_t<> operator<<(null<>);
|
||||||
|
void_t<> operator<<(const Char*);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Checks if T has a user-defined operator<< (e.g. not a member of
|
// Checks if T has a user-defined operator<< (e.g. not a member of
|
||||||
@ -56,9 +56,9 @@ template <typename Char> struct test_stream : std::basic_ostream<Char> {
|
|||||||
template <typename T, typename Char> class is_streamable {
|
template <typename T, typename Char> class is_streamable {
|
||||||
private:
|
private:
|
||||||
template <typename U>
|
template <typename U>
|
||||||
static decltype((void)(std::declval<test_stream<Char>&>()
|
static bool_constant<!std::is_same<decltype(std::declval<test_stream<Char>&>()
|
||||||
<< std::declval<U>()),
|
<< std::declval<U>()),
|
||||||
std::true_type())
|
void_t<>>::value>
|
||||||
test(int);
|
test(int);
|
||||||
|
|
||||||
template <typename> static std::false_type test(...);
|
template <typename> static std::false_type test(...);
|
||||||
|
@ -242,3 +242,15 @@ TEST(FormatTest, UDL) {
|
|||||||
EXPECT_EQ("{}"_format("test"), "test");
|
EXPECT_EQ("{}"_format("test"), "test");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct convertible {
|
||||||
|
T value;
|
||||||
|
explicit convertible(const T& val) : value(val) {}
|
||||||
|
operator T() const { return value; }
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(OStreamTest, ConvertibleToCString) {
|
||||||
|
EXPECT_EQ("x", fmt::format("{}", convertible<char>('x')));
|
||||||
|
EXPECT_EQ("foo", fmt::format("{}", convertible<const char*>("foo")));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user