From 090bfcf48c0d579c5b7c9f518dfc7f801c7a58ff Mon Sep 17 00:00:00 2001 From: Metehan Tuncbilek Date: Mon, 23 Sep 2024 17:00:48 +0300 Subject: [PATCH] std like protocols to make it work with std::algo for StableVector.hpp --- .../Data/Containers/StableVector.hpp | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/openVulkanoCpp/Data/Containers/StableVector.hpp b/openVulkanoCpp/Data/Containers/StableVector.hpp index ea57fa3..c2939d8 100644 --- a/openVulkanoCpp/Data/Containers/StableVector.hpp +++ b/openVulkanoCpp/Data/Containers/StableVector.hpp @@ -76,6 +76,27 @@ namespace OpenVulkano return temp; } + Iterator operator--() + { + --m_index; + MovetoNextValidChunk(); + return *this; + } + + Iterator operator--(int) + { + Iterator temp = *this; + --(*this); + return temp; + } + + template Iterator operator=(const Init& other) + { + m_ptr = other.m_ptr; + m_index = other.m_index; + return *this; + } + bool operator==(const Iterator& other) const { return m_ptr == other.m_ptr && m_index == other.m_index; } bool operator!=(const Iterator& other) const { return !(*this == other); } @@ -216,6 +237,16 @@ namespace OpenVulkano m_currentSize++; } + /** + * std version of PushBack(const T& value) + */ + void push_back(const T& value) { PushBack(value); } + + /** + * std version of PushBack(T&& value) + */ + void push_back(T&& value) { PushBack(std::move(value)); } + template void Emplace(Args&&... args) { VectorChunk* currentChunk = m_firstChunk; @@ -255,6 +286,11 @@ namespace OpenVulkano m_currentSize++; } + /** + * std version of EmplaceBack(Args&&... args) + */ + template void emplace_back(Args&&... args) { EmplaceBack(std::forward(args)...); } + /** * Pops the last element of the StableVector * @@ -279,6 +315,39 @@ namespace OpenVulkano m_currentSize--; } + /** + * std version of PopBack() + */ + void pop_back() { PopBack(); } + + constexpr T& Back() const + { + if (m_currentSize == 0) + { + throw std::out_of_range("Vector is empty!"); + } + return m_lastChunk->m_data[m_lastChunk->m_lastUsedIndex]; + } + + constexpr T& Front() const + { + if (m_currentSize == 0) + { + throw std::out_of_range("Vector is empty!"); + } + return m_firstChunk->m_data[0]; + } + + /** + * std version of Back() + */ + constexpr T& back() const { return Back(); } + + /** + * std version of Front() + */ + constexpr T& front() const { return Front(); } + void Remove(size_t index) { size_t localIndex = index; @@ -332,6 +401,7 @@ namespace OpenVulkano return vec; } + T& At(size_t index) const { if (index >= Size()) [[unlikely]] @@ -339,6 +409,9 @@ namespace OpenVulkano return (*this)[index]; } + bool Empty() const { return m_currentSize == 0; } + bool empty() const { return Empty(); } + T& operator[](size_t index) const { VectorChunk* chunk = m_firstChunk;