constexpr funny man

v1
Brett 2024-02-13 17:26:05 -05:00
parent c7beb41042
commit e1530de338
1 changed files with 24 additions and 24 deletions

View File

@ -98,18 +98,18 @@ namespace blt
using const_pointer = const T*; using const_pointer = const T*;
using reference = T&; using reference = T&;
using const_reference = const T&; using const_reference = const T&;
using iterator = T*; using iterator = ptr_iterator<T>;
using const_iterator = const T*; using const_iterator = ptr_iterator<const T>;
using reverse_iterator = std::reverse_iterator<iterator>; using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>;
private: private:
T* buffer_ = nullptr; T* buffer_ = nullptr;
size_t size_; size_t size_;
public: public:
scoped_buffer(): buffer_(nullptr), size_(0) constexpr scoped_buffer(): buffer_(nullptr), size_(0)
{} {}
explicit scoped_buffer(size_t size): size_(size) constexpr explicit scoped_buffer(size_t size): size_(size)
{ {
if (size > 0) if (size > 0)
buffer_ = new T[size]; buffer_ = new T[size];
@ -117,7 +117,7 @@ namespace blt
buffer_ = nullptr; buffer_ = nullptr;
} }
scoped_buffer(const scoped_buffer& copy) constexpr scoped_buffer(const scoped_buffer& copy)
{ {
if (copy.size() == 0) if (copy.size() == 0)
{ {
@ -143,7 +143,7 @@ namespace blt
} }
} }
scoped_buffer& operator=(const scoped_buffer& copy) constexpr scoped_buffer& operator=(const scoped_buffer& copy)
{ {
if (&copy == this) if (&copy == this)
return *this; return *this;
@ -175,7 +175,7 @@ namespace blt
return *this; return *this;
} }
scoped_buffer(scoped_buffer&& move) noexcept constexpr scoped_buffer(scoped_buffer&& move) noexcept
{ {
delete[] buffer_; delete[] buffer_;
buffer_ = move.buffer_; buffer_ = move.buffer_;
@ -183,7 +183,7 @@ namespace blt
move.buffer_ = nullptr; move.buffer_ = nullptr;
} }
scoped_buffer& operator=(scoped_buffer&& moveAssignment) noexcept constexpr scoped_buffer& operator=(scoped_buffer&& moveAssignment) noexcept
{ {
delete[] buffer_; delete[] buffer_;
buffer_ = moveAssignment.buffer_; buffer_ = moveAssignment.buffer_;
@ -193,42 +193,42 @@ namespace blt
return *this; return *this;
} }
inline T& operator[](size_t index) constexpr inline T& operator[](size_t index)
{ {
return buffer_[index]; return buffer_[index];
} }
inline const T& operator[](size_t index) const constexpr inline const T& operator[](size_t index) const
{ {
return buffer_[index]; return buffer_[index];
} }
inline T* operator*() constexpr inline T* operator*()
{ {
return buffer_; return buffer_;
} }
[[nodiscard]] inline size_t size() const [[nodiscard]] constexpr inline size_t size() const
{ {
return size_; return size_;
} }
inline T*& ptr() constexpr inline T*& ptr()
{ {
return buffer_; return buffer_;
} }
inline const T* const& ptr() const constexpr inline const T* const& ptr() const
{ {
return buffer_; return buffer_;
} }
inline const T* const& data() const constexpr inline const T* const& data() const
{ {
return buffer_; return buffer_;
} }
inline T*& data() constexpr inline T*& data()
{ {
return buffer_; return buffer_;
} }
@ -243,32 +243,32 @@ namespace blt
// return ptr_iterator{&buffer_[size_]}; // return ptr_iterator{&buffer_[size_]};
// } // }
constexpr iterator begin() const noexcept constexpr iterator begin() noexcept
{ {
return data(); return iterator{data()};
} }
constexpr iterator end() const noexcept constexpr iterator end() noexcept
{ {
return data() + size(); return iterator{data() + size()};
} }
constexpr const_iterator cbegin() const noexcept constexpr const_iterator cbegin() const noexcept
{ {
return data(); return const_iterator{data()};
} }
constexpr const_iterator cend() const noexcept constexpr const_iterator cend() const noexcept
{ {
return data() + size(); return const_iterator{data() + size()};
} }
constexpr reverse_iterator rbegin() const noexcept constexpr reverse_iterator rbegin() noexcept
{ {
return reverse_iterator{end()}; return reverse_iterator{end()};
} }
constexpr reverse_iterator rend() const noexcept constexpr reverse_iterator rend() noexcept
{ {
return reverse_iterator{begin()}; return reverse_iterator{begin()};
} }