std like protocols to make it work with std::algo for StableVector.hpp

This commit is contained in:
Metehan Tuncbilek
2024-09-23 17:00:48 +03:00
parent 02d84af907
commit 090bfcf48c

View File

@@ -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<typename Init> 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<typename... Args> void Emplace(Args&&... args)
{
VectorChunk* currentChunk = m_firstChunk;
@@ -255,6 +286,11 @@ namespace OpenVulkano
m_currentSize++;
}
/**
* std version of EmplaceBack(Args&&... args)
*/
template<typename... Args> void emplace_back(Args&&... args) { EmplaceBack(std::forward<Args>(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;