summaryrefslogtreecommitdiff
path: root/asl/buffer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'asl/buffer.hpp')
-rw-r--r--asl/buffer.hpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/asl/buffer.hpp b/asl/buffer.hpp
index e001ee0..74465bd 100644
--- a/asl/buffer.hpp
+++ b/asl/buffer.hpp
@@ -108,13 +108,16 @@ private:
}
public:
-
constexpr buffer() requires default_constructible<Allocator> = default;
explicit constexpr buffer(Allocator allocator)
: m_allocator{ASL_MOVE(allocator)}
{}
+ // @Todo Destructor
+ // @Todo clear
+ // @Todo Copy/move constructor & assignment
+
constexpr isize_t size() const
{
return decode_size(load_size_encoded());
@@ -150,7 +153,7 @@ public:
auto old_layout = layout::array<T>(old_capacity);
auto new_layout = layout::array<T>(new_capacity);
- if (currently_on_heap && trivially_copyable<T>)
+ if (currently_on_heap && trivially_move_constructible<T>)
{
m_data = reinterpret_cast<T*>(m_allocator.realloc(m_data, old_layout, new_layout));
m_capacity = new_capacity;
@@ -204,7 +207,18 @@ public:
}
}
- // @Todo operator[]
+ // @Todo(C++23) Use deducing this
+ constexpr T& operator[](isize_t i)
+ {
+ ASL_ASSERT(i >= 0 && i <= size());
+ return data()[i];
+ }
+
+ constexpr const T& operator[](isize_t i) const
+ {
+ ASL_ASSERT(i >= 0 && i <= size());
+ return data()[i];
+ }
};
} // namespace asl