mirror of
https://github.com/fmtlib/fmt.git
synced 2025-10-31 22:21:41 +01:00
Fix handling of types with custom formatters that are convertible to std::string_view
This commit is contained in:
committed by
Victor Zverovich
parent
4f4d876616
commit
1ab80aa92c
@@ -1685,6 +1685,28 @@ TEST(FormatterTest, FormatStdStringView) {
|
||||
EXPECT_EQ("test", format("{}", std::string_view("test")));
|
||||
EXPECT_EQ("foo", format("{}", string_viewable()));
|
||||
}
|
||||
|
||||
struct explicitly_convertible_to_std_string_view {
|
||||
explicit operator std::string_view() const { return "foo"; }
|
||||
};
|
||||
|
||||
namespace fmt {
|
||||
|
||||
template <>
|
||||
struct formatter<explicitly_convertible_to_std_string_view>
|
||||
: formatter<std::string_view> {
|
||||
auto format(const explicitly_convertible_to_std_string_view& v,
|
||||
format_context& ctx) {
|
||||
return format_to(ctx.out(), "'{}'", std::string_view(v));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace fmt
|
||||
|
||||
TEST(FormatterTest, FormatExplicitlyConvertibleToStdStringView) {
|
||||
EXPECT_EQ("'foo'",
|
||||
fmt::format("{}", explicitly_convertible_to_std_string_view()));
|
||||
}
|
||||
#endif
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user