From cf2719bd12f3dc5def4f004cb3dc132142bd5844 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 18 Jul 2018 19:12:10 -0700 Subject: [PATCH] Add support for types explicitly convertible to wstring_view --- include/fmt/core.h | 4 ++-- test/format-test.cc | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index c65709ac..404c03ef 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -676,13 +676,13 @@ template inline typename std::enable_if< std::is_constructible, T>::value, typed_value>::type - make_value(const T &val) { return string_view(val); } + make_value(const T &val) { return basic_string_view(val); } template inline typename std::enable_if< !convert_to_int::value && !std::is_convertible>::value && - !std::is_constructible::value, + !std::is_constructible, T>::value, // Implicit conversion to std::string is not handled here because it's // unsafe: https://github.com/fmtlib/fmt/issues/729 typed_value>::type diff --git a/test/format-test.cc b/test/format-test.cc index 2b720876..f6eecc72 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1103,6 +1103,14 @@ TEST(FormatterTest, FormatExplicitlyConvertibleToStringView) { 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 { template < typename String,