diff --git a/deps/ox/src/ox/std/iterator.hpp b/deps/ox/src/ox/std/iterator.hpp index 4b39f1f8..538f7397 100644 --- a/deps/ox/src/ox/std/iterator.hpp +++ b/deps/ox/src/ox/std/iterator.hpp @@ -9,6 +9,8 @@ #pragma once #ifndef OX_USE_STDLIB +#include "types.hpp" + namespace std { struct input_iterator_tag { @@ -29,12 +31,14 @@ struct random_access_iterator_tag: public bidirectional_iterator_tag { struct contiguous_iterator_tag: public random_access_iterator_tag { }; -template +template struct iterator { using iterator_category = Category; using value_type = T; using pointer = T*; using reference = T&; + using difference_type = DiffType; }; } diff --git a/deps/ox/src/ox/std/types.hpp b/deps/ox/src/ox/std/types.hpp index d64baada..e1763222 100644 --- a/deps/ox/src/ox/std/types.hpp +++ b/deps/ox/src/ox/std/types.hpp @@ -161,3 +161,9 @@ static_assert(sizeof(uint16_t) == 2, "uint16_t is wrong size"); static_assert(sizeof(uint32_t) == 4, "uint32_t is wrong size"); static_assert(sizeof(uint64_t) == 8, "uint64_t is wrong size"); static_assert(sizeof(uintptr_t) == sizeof(void*), "uintptr_t is wrong size"); + +#ifndef OX_USE_STDLIB +namespace std { +using ptrdiff_t = uintptr_t; +} +#endif \ No newline at end of file diff --git a/deps/ox/src/ox/std/vector.hpp b/deps/ox/src/ox/std/vector.hpp index 4d7a04f6..ca422340 100644 --- a/deps/ox/src/ox/std/vector.hpp +++ b/deps/ox/src/ox/std/vector.hpp @@ -101,6 +101,10 @@ class Vector: detail::SmallVector { m_max = max; } + constexpr auto offset() const noexcept { + return m_offset; + } + constexpr iterator operator+(size_type s) const noexcept { if constexpr(reverse) { return iterator(m_t, max(m_offset - s, 0), m_max); @@ -109,6 +113,15 @@ class Vector: detail::SmallVector { } } + constexpr typename std::iterator::difference_type + operator-(const iterator &other) const noexcept { + if constexpr(reverse) { + return m_offset + other.m_offset; + } else { + return m_offset - other.m_offset; + } + } + constexpr iterator operator-(size_type s) const noexcept { if constexpr(reverse) { return iterator(m_t, min(m_offset + s, m_max), m_max); @@ -187,9 +200,7 @@ class Vector: detail::SmallVector { explicit Vector(std::size_t size) noexcept; - #if __has_include() Vector(std::initializer_list list) noexcept; - #endif Vector(const Vector &other); @@ -279,6 +290,14 @@ class Vector: detail::SmallVector { void pop_back(); + /** + * Removes an item from the Vector. + * @param pos iterator at the point to remove + * @return Error if index is out of bounds + */ + template + Error erase(const iterator &pos); + /** * Removes an item from the Vector. * @param pos position of item to remove @@ -299,6 +318,14 @@ class Vector: detail::SmallVector { }; +template +using VectorIt = typename Vector::template iterator; + +template +VectorIt operator+(std::size_t n, const VectorIt &a) { + return a + n; +} + template Vector::Vector(std::size_t size) noexcept { m_size = size; @@ -522,6 +549,12 @@ void Vector::pop_back() { m_items[m_size].~T(); } +template +template +Error Vector::erase(const iterator &pos) { + return erase(pos.offset()); +} + template Error Vector::erase(std::size_t pos) { if (pos >= m_size) { @@ -554,9 +587,6 @@ void Vector::expandCap(std::size_t cap) { for (std::size_t i = 0; i < itRange; i++) { m_items[i] = move(oldItems[i]); } - for (std::size_t i = itRange; i < m_cap; i++) { - new (&m_items[i]) T; - } this->clearItems(bit_cast*>(oldItems)); } }