Created
          November 23, 2013 17:21 
        
      - 
      
- 
        Save vittorioromeo/7617402 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | template<typename T> class IdxIterator | |
| { | |
| private: | |
| T* container; | |
| std::size_t idx; | |
| public: | |
| inline IdxIterator(T* mContainer, std::size_t mIdx) noexcept : container{mContainer}, idx{mIdx} { } | |
| inline IdxIterator(const IdxIterator& mOther) noexcept = default; | |
| inline IdxIterator& operator=(const IdxIterator& mItr) noexcept = default; | |
| inline typename T::reference operator*() const noexcept { return (*container)[idx]; } | |
| inline IdxIterator& operator++() noexcept { ++idx; return *this; } | |
| inline IdxIterator& operator+=(std::size_t mStep) noexcept { idx += mStep; return *this; } | |
| inline IdxIterator& operator+=(const IdxIterator& mItr) noexcept { idx += mItr.idx; return *this; } | |
| inline IdxIterator& operator-=(std::size_t mStep) noexcept { idx -= mStep; return *this; } | |
| inline IdxIterator& operator-=(const IdxIterator& mItr) noexcept { idx -= mItr.idx; return *this; } | |
| inline bool operator<(const IdxIterator& mItr) const noexcept { return idx < mItr.idx; } | |
| inline bool operator>(const IdxIterator& mItr) const noexcept { return idx > mItr.idx; } | |
| inline bool operator<=(const IdxIterator& mItr) const noexcept { return idx <= mItr.idx; } | |
| inline bool operator>=(const IdxIterator& mItr) const noexcept { return idx >= mItr.idx; } | |
| inline bool operator==(const IdxIterator& mItr) const noexcept { return idx == mItr.idx; } | |
| inline bool operator!=(const IdxIterator& mItr) const noexcept { return idx != mItr.idx; } | |
| }; | |
| template<typename T> inline IdxIterator<T> operator+(IdxIterator<T> mA, const IdxIterator<T>& mB) noexcept { mA.idx += mB.idx; return mA; } | |
| template<typename T> inline IdxIterator<T> operator-(IdxIterator<T> mA, const IdxIterator<T>& mB) noexcept { mA.idx -= mB.idx; return mA; } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment