mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 19:24:48 +02:00
Add support for types explicitly convertible to wstring_view
This commit is contained in:
@@ -676,13 +676,13 @@ template <typename C, typename T, typename Char = typename C::char_type>
|
|||||||
inline typename std::enable_if<
|
inline typename std::enable_if<
|
||||||
std::is_constructible<basic_string_view<Char>, T>::value,
|
std::is_constructible<basic_string_view<Char>, T>::value,
|
||||||
typed_value<C, string_type>>::type
|
typed_value<C, string_type>>::type
|
||||||
make_value(const T &val) { return string_view(val); }
|
make_value(const T &val) { return basic_string_view<Char>(val); }
|
||||||
|
|
||||||
template <typename C, typename T, typename Char = typename C::char_type>
|
template <typename C, typename T, typename Char = typename C::char_type>
|
||||||
inline typename std::enable_if<
|
inline typename std::enable_if<
|
||||||
!convert_to_int<T, Char>::value &&
|
!convert_to_int<T, Char>::value &&
|
||||||
!std::is_convertible<T, basic_string_view<Char>>::value &&
|
!std::is_convertible<T, basic_string_view<Char>>::value &&
|
||||||
!std::is_constructible<string_view, T>::value,
|
!std::is_constructible<basic_string_view<Char>, T>::value,
|
||||||
// Implicit conversion to std::string is not handled here because it's
|
// Implicit conversion to std::string is not handled here because it's
|
||||||
// unsafe: https://github.com/fmtlib/fmt/issues/729
|
// unsafe: https://github.com/fmtlib/fmt/issues/729
|
||||||
typed_value<C, custom_type>>::type
|
typed_value<C, custom_type>>::type
|
||||||
|
@@ -1103,6 +1103,14 @@ TEST(FormatterTest, FormatExplicitlyConvertibleToStringView) {
|
|||||||
EXPECT_EQ("foo", format("{}", explicitly_convertible_to_string_view()));
|
EXPECT_EQ("foo", format("{}", explicitly_convertible_to_string_view()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct explicitly_convertible_to_wstring_view {
|
||||||
|
explicit operator fmt::wstring_view() const { return L"foo"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(FormatterTest, FormatExplicitlyConvertibleToWStringView) {
|
||||||
|
EXPECT_EQ(L"foo", format(L"{}", explicitly_convertible_to_wstring_view()));
|
||||||
|
}
|
||||||
|
|
||||||
struct explicitly_convertible_to_string_like {
|
struct explicitly_convertible_to_string_like {
|
||||||
template <
|
template <
|
||||||
typename String,
|
typename String,
|
||||||
|
Reference in New Issue
Block a user