From 5642cba31b5f7610eddf552b1acd984cf718340d Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Fri, 27 Dec 2024 19:19:40 +0100 Subject: Rework some metaprogramming stuff --- asl/buffer.hpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'asl/buffer.hpp') 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 = 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(old_capacity); auto new_layout = layout::array(new_capacity); - if (currently_on_heap && trivially_copyable) + if (currently_on_heap && trivially_move_constructible) { m_data = reinterpret_cast(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 -- cgit