mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-13 09:36:32 +00:00
Don't use ostream for types convertible to string_view
This commit is contained in:
parent
35c0286cd8
commit
31e743d06e
@ -9,7 +9,7 @@
|
||||
#define FMT_CORE_H_
|
||||
|
||||
#include <cstdio> // std::FILE
|
||||
#include <cstring>
|
||||
#include <cstring> // std::strlen
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
@ -45,7 +45,7 @@ struct is_streamable<
|
||||
enable_if_t<
|
||||
std::is_arithmetic<T>::value || std::is_array<T>::value ||
|
||||
std::is_pointer<T>::value || std::is_same<T, char8_type>::value ||
|
||||
std::is_same<T, std::basic_string<Char>>::value ||
|
||||
std::is_convertible<T, fmt::basic_string_view<Char>>::value ||
|
||||
std::is_same<T, std_string_view<Char>>::value ||
|
||||
(std::is_convertible<T, int>::value && !std::is_enum<T>::value)>>
|
||||
: std::false_type {};
|
||||
|
@ -262,6 +262,21 @@ TEST(ostream_test, format_convertible_to_bool) {
|
||||
EXPECT_EQ(fmt::format("{}", streamable_and_convertible_to_bool()), "true");
|
||||
}
|
||||
|
||||
struct streamable_and_convertible_to_string_view {
|
||||
operator fmt::string_view() const { return "foo"; }
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os,
|
||||
streamable_and_convertible_to_string_view) {
|
||||
return os << "bar";
|
||||
}
|
||||
|
||||
TEST(ostream_test, format_convertible_to_string_vew) {
|
||||
// operator<< is intentionally not used because of potential ODR violations.
|
||||
EXPECT_EQ(fmt::format("{}", streamable_and_convertible_to_string_view()),
|
||||
"foo");
|
||||
}
|
||||
|
||||
struct copyfmt_test {};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, copyfmt_test) {
|
||||
|
Loading…
Reference in New Issue
Block a user