From 2a09bbc8f813d28d69768ba9375b637e2ba8bd8d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 24 Aug 2026 16:57:24 +0200 Subject: kernel/fs: ext2: cosmetic cleanup --- libs/kstd/kstd/span.hpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 libs/kstd/kstd/span.hpp (limited to 'libs') diff --git a/libs/kstd/kstd/span.hpp b/libs/kstd/kstd/span.hpp new file mode 100644 index 00000000..6be2eea2 --- /dev/null +++ b/libs/kstd/kstd/span.hpp @@ -0,0 +1,57 @@ +#ifndef KSTD_SPAN_HPP +#define KSTD_SPAN_HPP + +#include +#include +#include // IWYU pragma: export + +namespace kstd +{ + + //! Get a read-only span of bytes, that maps to a given object + //! + //! @param object The object to obtain the byte span for. + //! @return A span over the raw bytes of the object representation of the given object. + template + requires(!std::ranges::range) + constexpr auto raw_bytes(ObjectType const & object) -> std::span + { + return std::as_bytes(std::span{std::addressof(object), 1}); + } + + //! Get a read-write span of bytes, that maps to a given object + //! + //! @param object The object to obtain the byte span for. + //! @return A span over the raw bytes of the object representation of the given object. + template + requires(!std::ranges::range) + constexpr auto raw_bytes(ObjectType & object) -> std::span + { + return std::as_writable_bytes(std::span{std::addressof(object), 1}); + } + + //! Get a read-only span of bytes, that maps to a given range object + //! + //! @param range The range of objects to obtain the byte span for. + //! @return A span over the raw bytes of the object representation of the given object. + template + requires(std::ranges::range) + constexpr auto raw_bytes(ObjectType const & range) -> std::span + { + return std::as_bytes(std::span{range}); + } + + //! Get a read-write span of bytes, that maps to a given range object + //! + //! @param range The range of objects to obtain the byte span for. + //! @return A span over the raw bytes of the object representation of the given object. + template + requires(std::ranges::range) + constexpr auto raw_bytes(ObjectType & range) -> std::span + { + return std::as_writable_bytes(std::span{range}); + } + +} // namespace kstd + +#endif \ No newline at end of file -- cgit v1.2.3