فهرست منبع

AK: Add a Stream::write_until_depleted overload for string types

All string types currently have to invoke this function as:

    stream.write_until_depleted("foo"sv.bytes());

This isn't very ergonomic, but more importantly, this overload will
allow String/ByteString instances to be written in this manner once
e.g. `ByteString::view() &&` is deleted.
Timothy Flynn 1 سال پیش
والد
کامیت
e0bddbb65e
1فایلهای تغییر یافته به همراه8 افزوده شده و 0 حذف شده
  1. 8 0
      AK/Stream.h

+ 8 - 0
AK/Stream.h

@@ -7,9 +7,11 @@
 
 #pragma once
 
+#include <AK/Concepts.h>
 #include <AK/Error.h>
 #include <AK/Format.h>
 #include <AK/Forward.h>
+#include <AK/StringView.h>
 #include <AK/Traits.h>
 
 namespace AK {
@@ -47,6 +49,12 @@ public:
     /// contents are written or an error occurs.
     virtual ErrorOr<void> write_until_depleted(ReadonlyBytes);
 
+    template<Concepts::AnyString T>
+    ErrorOr<void> write_until_depleted(T const& buffer)
+    {
+        return write_until_depleted(StringView { buffer }.bytes());
+    }
+
     template<typename T>
     requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs<ErrorOr<T>>; })
     ErrorOr<T> read_value()