From c7beb410423f6fb5e00f4fc3cceeb2d02564f995 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Tue, 13 Feb 2024 17:06:33 -0500 Subject: [PATCH] more tricks to the buffer --- include/blt/std/memory.h | 59 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/include/blt/std/memory.h b/include/blt/std/memory.h index a3e4969..f540619 100755 --- a/include/blt/std/memory.h +++ b/include/blt/std/memory.h @@ -91,6 +91,17 @@ namespace blt template || std::is_copy_assignable_v> class scoped_buffer { + public: + using element_type = T; + using value_type = std::remove_cv_t; + using pointer = T*; + using const_pointer = const T*; + using reference = T&; + using const_reference = const T&; + using iterator = T*; + using const_iterator = const T*; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; private: T* buffer_ = nullptr; size_t size_; @@ -222,16 +233,56 @@ namespace blt return buffer_; } - inline ptr_iterator begin() +// inline auto begin() +// { +// return ptr_iterator{buffer_}; +// } +// +// inline ptr_iterator end() +// { +// return ptr_iterator{&buffer_[size_]}; +// } + + constexpr iterator begin() const noexcept { - return ptr_iterator{buffer_}; + return data(); } - inline ptr_iterator end() + constexpr iterator end() const noexcept { - return ptr_iterator{&buffer_[size_]}; + return data() + size(); } + constexpr const_iterator cbegin() const noexcept + { + return data(); + } + + constexpr const_iterator cend() const noexcept + { + return data() + size(); + } + + constexpr reverse_iterator rbegin() const noexcept + { + return reverse_iterator{end()}; + } + + constexpr reverse_iterator rend() const noexcept + { + return reverse_iterator{begin()}; + } + + constexpr const_reverse_iterator crbegin() const noexcept + { + return reverse_iterator{cend()}; + } + + constexpr const_reverse_iterator crend() const noexcept + { + return reverse_iterator{cbegin()}; + } + ~scoped_buffer() { delete[] buffer_;