summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-12-08 08:08:08 -0500
committerAndreas Kling <kling@serenityos.org>2022-12-08 17:14:48 +0100
commit949f5460fb8ab73512b7f721cee99440fa956e56 (patch)
treee0305acc660961fe5a61761ad0342d956a82cbaa /AK
parentc3720128420556789d2c78cb592e4919bac129de (diff)
downloadserenity-949f5460fb8ab73512b7f721cee99440fa956e56.zip
AK: Add formatters for Span<T> and Span<T const>
This generalizes the formatter currently used for Vector to be usable for any Span.
Diffstat (limited to 'AK')
-rw-r--r--AK/Format.h27
1 files changed, 23 insertions, 4 deletions
diff --git a/AK/Format.h b/AK/Format.h
index b493b3c557..48682c2dbe 100644
--- a/AK/Format.h
+++ b/AK/Format.h
@@ -329,15 +329,16 @@ struct Formatter<StringView> : StandardFormatter {
ErrorOr<void> format(FormatBuilder&, StringView);
};
-template<typename T, size_t inline_capacity>
-requires(HasFormatter<T>) struct Formatter<Vector<T, inline_capacity>> : StandardFormatter {
-
+template<typename T>
+requires(HasFormatter<T>)
+struct Formatter<Span<T const>> : StandardFormatter {
Formatter() = default;
explicit Formatter(StandardFormatter formatter)
: StandardFormatter(move(formatter))
{
}
- ErrorOr<void> format(FormatBuilder& builder, Vector<T> value)
+
+ ErrorOr<void> format(FormatBuilder& builder, Span<T const> value)
{
if (m_mode == Mode::Pointer) {
Formatter<FlatPtr> formatter { *this };
@@ -375,6 +376,24 @@ requires(HasFormatter<T>) struct Formatter<Vector<T, inline_capacity>> : Standar
}
};
+template<typename T>
+requires(HasFormatter<T>)
+struct Formatter<Span<T>> : Formatter<Span<T const>> {
+ ErrorOr<void> format(FormatBuilder& builder, Span<T> value)
+ {
+ return Formatter<Span<T const>>::format(builder, value);
+ }
+};
+
+template<typename T, size_t inline_capacity>
+requires(HasFormatter<T>)
+struct Formatter<Vector<T, inline_capacity>> : Formatter<Span<T const>> {
+ ErrorOr<void> format(FormatBuilder& builder, Vector<T, inline_capacity> const& value)
+ {
+ return Formatter<Span<T const>>::format(builder, value.span());
+ }
+};
+
template<>
struct Formatter<ReadonlyBytes> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, ReadonlyBytes value)