diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-27 19:19:40 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-28 12:53:01 +0100 |
commit | 5642cba31b5f7610eddf552b1acd984cf718340d (patch) | |
tree | 40dcec36191f4ed8040c6b6f7525cee978b18fa1 /asl/buffer.hpp | |
parent | 006a09335306da53f32b4662ebc77866427b6841 (diff) |
Rework some metaprogramming stuff
Diffstat (limited to 'asl/buffer.hpp')
-rw-r--r-- | asl/buffer.hpp | 20 |
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
|