⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dense_iterator.h

📁 很好用的库
💻 H
📖 第 1 页 / 共 2 页
字号:
  //!wheredef: IndexedIterator  inline size_type index() const {     return pos + start_index + IND_OFFSET;   }  //: Default Constructor    inline dense_iterator() : pos(0), start_index(0) {}  //: Constructor from underlying iterator  inline dense_iterator(RandomAccessIterator s, 			size_type i, size_type first_index = 0)    : RandomAccessIterator(s), pos(i), start_index(first_index) { }  //: Copy Constructor    inline dense_iterator (const self& x)     : RandomAccessIterator(x), pos(x.pos), start_index(x.start_index) {}  template <class SELF>  inline dense_iterator (const SELF& x)    : RandomAccessIterator(x), pos(x.pos), start_index(x.start_index) {}  //: Assignment operator  inline self& operator=(const self& x) {	  RandomAccessIterator::operator=( x );	  pos = x.pos;	  start_index = x.start_index;      return *this;  }  //: Destructor  inline ~dense_iterator () { }  //: Access the underlying iterator    inline RandomAccessIterator base() const { return start() + pos; }  inline operator RandomAccessIterator() const { return start() + pos; }  //: Dereference operator    inline reference operator*() const { return *(start() + pos);  }  //: Member access operator  inline pointer operator-> () const { return start() + pos; }  //: Pre-increment operator    inline self& operator++ () { ++pos; return *this; }  //: Post-increment operator  inline self operator++ (int) { self tmp = *this; ++pos; return tmp; }  //: Pre-decrement operator  inline self& operator-- () { --pos; return *this; }  //: Post-decrement operator  inline self operator-- (int) { self tmp = *this; --pos; return tmp; }  //: Add iterator and distance n  inline self operator+ (Distance n) const { return self(start(), pos + n); }  //: Add distance n to this iterator  inline self& operator+= (Distance n) { pos += n; return *this; }  //: Subtract iterator and distance n  inline self operator- (Distance n) const { return self(start(), pos - n); }  //: Return the difference between two iterators  inline difference_type operator- (const self& x) const {     return base() - x.base(); }  //: Subtract distance n from this iterator  inline self& operator-= (Distance n) { pos -= n; return *this; }  //: Return whether this iterator is not equal to iterator x  inline bool operator!= (const self& x) const { return pos != x.pos; }  //: Return whether this iterator is less than iterator x  inline bool operator < (const self& x) const { return pos < x.pos; }  //: Return whether this iterator is greater than iterator x  inline bool operator > (const self& x) const { return pos > x.pos; }  //: Return whether this iterator is equal to iterator x  inline bool operator== (const self& x) const { return pos == x.pos; }  //: Return whether this iterator is less than or equal to iterator x  inline bool operator<= (const self& x) const { return pos <= x.pos; }  //: Return whether this iterator is greater than or equal to iterator x  inline bool operator>= (const self& x) const { return pos >= x.pos; }  //: Equivalent to *(i + n)  inline reference operator[] (Distance n) const {     return *(start() + pos + n);   }};template <class T, int OS, class ST>inlinedense_iterator<T>operator+ (typename dense_iterator<T,OS,ST>::size_type n, 	   const dense_iterator<T,OS,ST> &x){  return dense_iterator<T,OS,ST>(x.base(), n);}#else // other compilerstemplate <class RandomAccessIterator, int IND_OFFSET=0, class SizeType=int>class dense_iterator {  typedef dense_iterator self;public:  //: The value type  typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;  //: This is a random access iterator  typedef typename std::iterator_traits<RandomAccessIterator>::iterator_category iterator_category;  //: The type for differences between iterators  typedef typename std::iterator_traits<RandomAccessIterator>::difference_type difference_type;  //: The type for pointers to the value type  typedef typename std::iterator_traits<RandomAccessIterator>::pointer pointer;  //: The type for references to the value type  typedef typename std::iterator_traits<RandomAccessIterator>::reference reference;  typedef difference_type Distance;  typedef SizeType size_type;    /*protected:*/  RandomAccessIterator start;  size_type pos;  size_type start_index;public:  //: Return the index of the current element  //!wheredef: IndexedIterator  inline size_type index() const {     return pos + start_index + IND_OFFSET;   }  //: Default Constructor    inline dense_iterator() : pos(0), start_index(0) {}  //: Constructor from underlying iterator  inline dense_iterator(RandomAccessIterator s, 			size_type i, size_type first_index = 0)    : start(s), pos(i), start_index(first_index) { }  //: Copy Constructor    inline dense_iterator (const self& x)     : start(x.start), pos(x.pos), start_index(x.start_index) {}  template <class SELF>  inline dense_iterator (const SELF& x)    : start(x.start), pos(x.pos), start_index(x.start_index) {}  //: Assignment operator  inline self& operator=(const self& x) {    start = x.start;    pos = x.pos;    start_index = x.start_index;    return *this;  }  //: Destructor  inline ~dense_iterator () { }  //: Access the underlying iterator    inline RandomAccessIterator base() const { return start + pos; }  inline operator RandomAccessIterator() const { return start + pos; }  //: Dereference operator    inline reference operator*() const { return *(start + pos);  }  //: Member access operator  inline pointer operator-> () const { return start + pos; }  //: Pre-increment operator    inline self& operator++ () { ++pos; return *this; }  //: Post-increment operator  inline self operator++ (int) { self tmp = *this; ++pos; return tmp; }  //: Pre-decrement operator  inline self& operator-- () { --pos; return *this; }  //: Post-decrement operator  inline self operator-- (int) { self tmp = *this; --pos; return tmp; }  //: Add iterator and distance n  inline self operator+ (Distance n) const { return self(start, pos + n); }  //: Add distance n to this iterator  inline self& operator+= (Distance n) { pos += n; return *this; }  //: Subtract iterator and distance n  inline self operator- (Distance n) const { return self(start, pos - n); }  //: Return the difference between two iterators  inline difference_type operator- (const self& x) const {     return base() - x.base(); }  //: Subtract distance n from this iterator  inline self& operator-= (Distance n) { pos -= n; return *this; }  //: Return whether this iterator is not equal to iterator x  inline bool operator!= (const self& x) const { return pos != x.pos; }  //: Return whether this iterator is less than iterator x  inline bool operator < (const self& x) const { return pos < x.pos; }  //: Return whether this iterator is greater than iterator x  inline bool operator > (const self& x) const { return pos > x.pos; }  //: Return whether this iterator is equal to iterator x  inline bool operator== (const self& x) const { return pos == x.pos; }  //: Return whether this iterator is less than or equal to iterator x  inline bool operator<= (const self& x) const { return pos <= x.pos; }  //: Return whether this iterator is greater than or equal to iterator x  inline bool operator>= (const self& x) const { return pos >= x.pos; }  //: Equivalent to *(i + n)  inline reference operator[] (Distance n) const {     return *(start + pos + n);   }};template <class T, int OS, class ST>inlinedense_iterator<T>operator+ (typename dense_iterator<T,OS,ST>::size_type n, 	   const dense_iterator<T,OS,ST> &x){  return dense_iterator<T,OS,ST>(x.base(), n);}#endif} /* namespace mtl */#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -