From 5682cb422c39eea6b4d5d54c2f31260785dc256f Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 4 Nov 2024 13:19:11 +0100 Subject: Start work on span --- asl/span.hpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 asl/span.hpp (limited to 'asl/span.hpp') diff --git a/asl/span.hpp b/asl/span.hpp new file mode 100644 index 0000000..f3d4036 --- /dev/null +++ b/asl/span.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include "asl/meta.hpp" +#include "asl/annotations.hpp" +#include "asl/layout.hpp" + +namespace asl +{ + +static constexpr int64_t dynamic_size = -1; + +template +class span +{ + static constexpr bool kIsDynamic = kSize < 0; + + using SizeType = select_t; + + T* m_data{}; + ASL_NO_UNIQUE_ADDRESS SizeType m_size{}; + +public: + constexpr span() = default; + + constexpr span(const span&) = default; + constexpr span(span&&) = default; + + constexpr span& operator=(const span&) = default; + constexpr span& operator=(span&&) = default; + + ~span() = default; + + constexpr int64_t size() const + { + if constexpr (kIsDynamic) { return m_size; } + else { return kSize; } + } + + constexpr int64_t size_bytes() const { return size() * size_of; } + + constexpr bool is_empty() const { return size() == 0; } +}; + +} // namespace asl -- cgit