summaryrefslogtreecommitdiff
path: root/asl/span.hpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-11-04 13:19:11 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-12-20 15:35:58 +0100
commit5682cb422c39eea6b4d5d54c2f31260785dc256f (patch)
treeebadbbb0a5af47f309766ccf63474f097c08743f /asl/span.hpp
parent6726a96f0cf3c230e9caa2abd40fcfbf03fe73a4 (diff)
Start work on span
Diffstat (limited to 'asl/span.hpp')
-rw-r--r--asl/span.hpp44
1 files changed, 44 insertions, 0 deletions
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<is_object T, int64_t kSize = dynamic_size>
+class span
+{
+ static constexpr bool kIsDynamic = kSize < 0;
+
+ using SizeType = select_t<kIsDynamic, int64_t, empty>;
+
+ 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<T>; }
+
+ constexpr bool is_empty() const { return size() == 0; }
+};
+
+} // namespace asl