Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class MyIter : public std::iterator<std::random_access_iterator_tag, T>{
- public:
- typedef MyIter<T> iterator;
- typedef T* pointer;
- MyIter(pointer ptr = nullptr):m_data(ptr){}
- T& operator*(){return *m_data;}
- iterator& operator++(){++m_data; return *this;}
- iterator operator++(int){
- iterator tmp = m_data;
- ++m_data;
- return tmp;
- }
- iterator& operator--(){--m_data; return *this;}
- iterator operator--(int){
- iterator tmp = m_data;
- --m_data;
- return tmp;
- }
- bool operator<(const MyIter& rhs){return m_data<rhs.m_data;}
- MyIter<T> operator-(const MyIter<T>& rhs){
- MyIter<T> tmp = *this;
- tmp.m_data-=rhs.m_data;
- return tmp;
- }
- MyIter<T> operator+(const MyIter<T>& rhs){
- MyIter<T> tmp = *this;
- tmp.m_data+=rhs.m_data;
- return tmp;
- }
- MyIter<T> operator+=(const MyIter<T>& movement)
- {
- m_data += movement.m_data;
- return *this;
- }
- MyIter<T>& operator-=(const MyIter<T>& movement)
- {
- m_data -= movement.m_data;
- return *this;
- }
- std::ptrdiff_t operator-(MyIter<T> const& rhs) const{
- auto old = m_data;
- m_data -= rhs.m_data;
- auto temp = *this;
- m_data = old;
- return temp.m_data;
- }
- MyIter& operator=(const MyIter<T>& rhs){
- this->m_data = rhs.m_data;
- return *this;
- }
- bool operator==(const MyIter& rhs) const{return m_data==rhs.m_data;}
- bool operator!=(const MyIter& rhs) const{return !((*this)==rhs);}
- pointer m_data;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement