diff --git a/CMakeLists.txt b/CMakeLists.txt index fa9d1ef..42f06c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.17.24) +set(BLT_VERSION 0.17.25) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/std/memory_util.h b/include/blt/std/memory_util.h index cf61546..6344b11 100644 --- a/include/blt/std/memory_util.h +++ b/include/blt/std/memory_util.h @@ -19,6 +19,7 @@ #ifndef BLT_MEMORY_UTIL_H #define BLT_MEMORY_UTIL_H +#include #include #include #include @@ -140,19 +141,24 @@ namespace blt { public: using iterator_category = std::random_access_iterator_tag; - using difference_type = std::ptrdiff_t; + using difference_type = blt::ptrdiff_t; using value_type = V; using pointer = value_type*; using reference = value_type&; + using iter_reference = ptr_iterator&; explicit ptr_iterator(V* v): _v(v) {} reference operator*() const - { return *_v; } + { + return *_v; + } pointer operator->() - { return _v; } + { + return _v; + } ptr_iterator& operator++() { @@ -180,6 +186,63 @@ namespace blt return tmp; } + iter_reference operator+=(difference_type amount) + { + _v += amount; + return *this; + } + + iter_reference operator-=(difference_type amount) + { + _v -= amount; + return *this; + } + + reference operator[](difference_type index) + { + return *(_v + index); + } + + reference operator[](blt::size_t index) + { + return *(_v + index); + } + + friend bool operator<(const ptr_iterator& a, const ptr_iterator& b) + { + return b._v - a._v > 0; + } + + friend bool operator>(const ptr_iterator& a, const ptr_iterator& b) + { + return a._v - b._v > 0; + } + + friend bool operator<=(const ptr_iterator& a, const ptr_iterator& b) + { + return b._v - a._v >= 0; + } + + friend bool operator>=(const ptr_iterator& a, const ptr_iterator& b) + { + return a._v - b._v >= 0; + } + + friend difference_type operator-(const ptr_iterator& a, const ptr_iterator& b) + { + return a._v - b._v; + } + + friend ptr_iterator operator+(const ptr_iterator& a, difference_type n) + { + return ptr_iterator(a._v + n); + } + + friend ptr_iterator operator+(difference_type n, const ptr_iterator& a) + { + return ptr_iterator(a._v + n); + } + friend bool operator==(const ptr_iterator& a, const ptr_iterator& b) { return a._v == b._v; diff --git a/include/blt/std/vector.h b/include/blt/std/vector.h index 7987116..1665072 100644 --- a/include/blt/std/vector.h +++ b/include/blt/std/vector.h @@ -258,6 +258,18 @@ namespace blt size_ -= remove_amount; return buffer_ + first_pos + 1; } + + template, bool> = true> + constexpr friend bool operator==(const static_vector& v1, const static_vector& v2) + { + if (v1.size() != v2.size()) + return false; + for (blt::size_t i = 0; i < v1.size(); i++) { + if (v1[i] != v2[i]) + return false; + } + return true; + } }; template> @@ -277,8 +289,8 @@ namespace blt using const_reference = const value_type&; using pointer = value_type*; using const_pointer = const pointer; - using iterator = T*; - using const_iterator = const T*; + using iterator = blt::ptr_iterator; + using const_iterator = blt::ptr_iterator; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator;