(This is the Non-const version, I have to implement the const one too). Could someone please review this implementation? This is made for std::vector I'm unsure whether I respected all requirements for LegacyRandomAccessIterator; so if I'm missing something, please do let me know.
namespace random_access
{
template<typename Type>
class iterator
{
private:
Type* m_iterator;
public:
using value_type = Type;
using reference = value_type&;
using pointer = value_type*;
using iterator_category = std::random_access_iterator_tag;
using difference_type = std::ptrdiff_t;
//using iterator_concept = std::contiguous_iterator_tag;
constexpr iterator(Type* iter = nullptr) : m_iterator{ iter } {}
constexpr bool operator==(const iterator& other) const noexcept { return m_iterator == other.m_iterator; }
constexpr bool operator!=(const iterator& other) const noexcept { return m_iterator != other.m_iterator; }
constexpr reference operator*() const noexcept { return *m_iterator; }
constexpr pointer operator->() const noexcept { return m_iterator; }
constexpr iterator& operator++() noexcept { ++m_iterator; return *this; }
constexpr iterator operator++(int) noexcept { iterator tmp(*this); ++(*this); return tmp; }
constexpr iterator& operator--() noexcept { --m_iterator; return *this; }
constexpr iterator operator--(int) noexcept { iterator tmp(*this); --(*this); return tmp; }
constexpr iterator& operator+=(const difference_type other) noexcept { m_iterator += other; return *this; }
constexpr iterator& operator-=(const difference_type other) noexcept { m_iterator -= other; return *this; }
constexpr iterator operator+(const difference_type other) const noexcept { return iterator(m_iterator + other); }
constexpr iterator operator-(const difference_type other) const noexcept { return iterator(m_iterator - other); }
constexpr iterator operator+(const iterator& other) const noexcept { return iterator(*this + other.m_iterator); }
constexpr difference_type operator-(const iterator& other) const noexcept { return std::distance(m_iterator, other.m_iterator); }
constexpr reference operator[](std::size_t index) const { return m_iterator[index]; }
constexpr bool operator<(const iterator& other) const noexcept { return m_iterator < other.m_iterator; }
constexpr bool operator>(const iterator& other) const noexcept { return m_iterator > other.m_iterator; }
constexpr bool operator<=(const iterator& other) const noexcept { return m_iterator <= other.m_iterator; }
constexpr bool operator>=(const iterator& other) const noexcept { return m_iterator >= other.m_iterator; }
};
}
Thanks !
iterator operator+(const iterator& other)
That does not seem to have any meaning. \$\endgroup\$