mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Add formatter<std::string_view>
This commit is contained in:
@ -3005,6 +3005,7 @@ FMT_FORMAT_AS(float, double);
|
|||||||
FMT_FORMAT_AS(Char*, const Char*);
|
FMT_FORMAT_AS(Char*, const Char*);
|
||||||
FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
|
FMT_FORMAT_AS(std::basic_string<Char>, basic_string_view<Char>);
|
||||||
FMT_FORMAT_AS(std::nullptr_t, const void*);
|
FMT_FORMAT_AS(std::nullptr_t, const void*);
|
||||||
|
FMT_FORMAT_AS(internal::std_string_view<Char>, basic_string_view<Char>);
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
struct formatter<void*, Char> : formatter<const void*, Char> {
|
struct formatter<void*, Char> : formatter<const void*, Char> {
|
||||||
|
@ -1590,9 +1590,20 @@ TEST(FormatterTest, FormatStringView) {
|
|||||||
EXPECT_EQ("", format("{}", string_view()));
|
EXPECT_EQ("", format("{}", string_view()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FMT_USE_STD_STRING_VIEW
|
#ifdef FMT_USE_STRING_VIEW
|
||||||
|
struct string_viewable {};
|
||||||
|
|
||||||
|
FMT_BEGIN_NAMESPACE
|
||||||
|
template <> struct formatter<string_viewable> : formatter<std::string_view> {
|
||||||
|
auto format(string_viewable, format_context& ctx) -> decltype(ctx.out()) {
|
||||||
|
return formatter<std::string_view>::format("foo", ctx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
TEST(FormatterTest, FormatStdStringView) {
|
TEST(FormatterTest, FormatStdStringView) {
|
||||||
EXPECT_EQ("test", format("{0}", std::string_view("test")));
|
EXPECT_EQ("test", format("{}", std::string_view("test")));
|
||||||
|
EXPECT_EQ("foo", format("{}", string_viewable()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user