📄 iterator.hpp
字号:
BOOST_UBLAS_INLINE
reference operator * () const {
BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());
BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());
return (*this) () (it1_, it2_);
}
BOOST_UBLAS_INLINE
reference operator [] (difference_type n) const {
return *((*this) + n);
}
// Index
BOOST_UBLAS_INLINE
size_type index1 () const {
return it1_;
}
BOOST_UBLAS_INLINE
size_type index2 () const {
return it2_;
}
BOOST_UBLAS_INLINE
dual_iterator_type begin () const {
return (*this) ().find2 (1, index1 (), 0);
}
BOOST_UBLAS_INLINE
dual_iterator_type end () const {
return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
}
BOOST_UBLAS_INLINE
dual_reverse_iterator_type rbegin () const {
return dual_reverse_iterator_type (end ());
}
BOOST_UBLAS_INLINE
dual_reverse_iterator_type rend () const {
return dual_reverse_iterator_type (begin ());
}
// Assignment
BOOST_UBLAS_INLINE
indexed_iterator1 &operator = (const indexed_iterator1 &it) {
// FIX: ICC needs full qualification?!
// assign (&it ());
container_reference<C>::assign (&it ());
it1_ = it.it1_;
it2_ = it.it2_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const indexed_iterator1 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
return it1_ == it.it1_;
}
BOOST_UBLAS_INLINE
bool operator < (const indexed_iterator1 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
return it1_ < it.it1_;
}
private:
size_type it1_;
size_type it2_;
};
#ifdef BOOST_MSVC_STD_ITERATOR
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_iterator1<C, I> operator ++ (const indexed_iterator1<C, I> &it, int) {
indexed_iterator1<C, I> tmp (it);
++ tmp;
return tmp;
}
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_iterator1<C, I> operator -- (const indexed_iterator1<C, I> &it, int) {
indexed_iterator1<C, I> tmp (it);
-- tmp;
return tmp;
}
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_iterator1<C, I> operator + (const indexed_iterator1<C, I> &it, std::ptrdiff_t n) {
indexed_iterator1<C, I> tmp (it);
return tmp += n;
}
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_iterator1<C, I> operator + (std::ptrdiff_t n, const indexed_iterator1<C, I> &it) {
indexed_iterator1<C, I> tmp (it);
return tmp += n;
}
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_iterator1<C, I> operator - (const indexed_iterator1<C, I> &it, std::ptrdiff_t n) {
indexed_iterator1<C, I> tmp (it);
return tmp -= n;
}
#endif
template<class C, class IC>
class indexed_const_iterator2;
template<class C, class IC>
class indexed_const_iterator1:
public container_const_reference<C>,
public random_access_iterator_base<IC,
indexed_const_iterator1<C, IC>,
typename C::value_type,
typename C::const_reference> {
public:
typedef C container_type;
typedef IC iterator_category;
typedef typename container_type::size_type size_type;
typedef typename container_type::difference_type difference_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::const_reference reference;
typedef indexed_iterator1<container_type, iterator_category> iterator_type;
typedef indexed_const_iterator2<container_type, iterator_category> dual_iterator_type;
#ifdef BOOST_MSVC_STD_ITERATOR
typedef reverse_iterator_base2<dual_iterator_type, value_type, reference> dual_reverse_iterator_type;
#else
typedef reverse_iterator_base2<dual_iterator_type> dual_reverse_iterator_type;
#endif
// Construction and destruction
BOOST_UBLAS_INLINE
indexed_const_iterator1 ():
container_const_reference<container_type> (), it1_ (), it2_ () {}
BOOST_UBLAS_INLINE
indexed_const_iterator1 (const container_type &c, size_type it1, size_type it2):
container_const_reference<container_type> (c), it1_ (it1), it2_ (it2) {}
BOOST_UBLAS_INLINE
indexed_const_iterator1 (const iterator_type &it):
container_const_reference<container_type> (it ()), it1_ (it.index1 ()), it2_ (it.index2 ()) {}
// Arithmetic
BOOST_UBLAS_INLINE
indexed_const_iterator1 &operator ++ () {
++ it1_;
return *this;
}
BOOST_UBLAS_INLINE
indexed_const_iterator1 &operator -- () {
-- it1_;
return *this;
}
BOOST_UBLAS_INLINE
indexed_const_iterator1 &operator += (difference_type n) {
it1_ += n;
return *this;
}
BOOST_UBLAS_INLINE
indexed_const_iterator1 &operator -= (difference_type n) {
it1_ -= n;
return *this;
}
BOOST_UBLAS_INLINE
difference_type operator - (const indexed_const_iterator1 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
return it1_ - it.it1_;
}
// Dereference
BOOST_UBLAS_INLINE
reference operator * () const {
BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());
BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());
return (*this) () (it1_, it2_);
}
BOOST_UBLAS_INLINE
reference operator [] (difference_type n) const {
return *((*this) + n);
}
// Index
BOOST_UBLAS_INLINE
size_type index1 () const {
return it1_;
}
BOOST_UBLAS_INLINE
size_type index2 () const {
return it2_;
}
BOOST_UBLAS_INLINE
dual_iterator_type begin () const {
return (*this) ().find2 (1, index1 (), 0);
}
BOOST_UBLAS_INLINE
dual_iterator_type end () const {
return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
}
BOOST_UBLAS_INLINE
dual_reverse_iterator_type rbegin () const {
return dual_reverse_iterator_type (end ());
}
BOOST_UBLAS_INLINE
dual_reverse_iterator_type rend () const {
return dual_reverse_iterator_type (begin ());
}
// Assignment
BOOST_UBLAS_INLINE
indexed_const_iterator1 &operator = (const indexed_const_iterator1 &it) {
// FIX: ICC needs full qualification?!
// assign (&it ());
container_const_reference<C>::assign (&it ());
it1_ = it.it1_;
it2_ = it.it2_;
return *this;
}
// Comparison
BOOST_UBLAS_INLINE
bool operator == (const indexed_const_iterator1 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
return it1_ == it.it1_;
}
BOOST_UBLAS_INLINE
bool operator < (const indexed_const_iterator1 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
return it1_ < it.it1_;
}
private:
size_type it1_;
size_type it2_;
friend class indexed_iterator1<container_type, iterator_category>;
};
#ifdef BOOST_MSVC_STD_ITERATOR
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_const_iterator1<C, I> operator ++ (const indexed_const_iterator1<C, I> &it, int) {
indexed_const_iterator1<C, I> tmp (it);
++ tmp;
return tmp;
}
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_const_iterator1<C, I> operator -- (const indexed_const_iterator1<C, I> &it, int) {
indexed_const_iterator1<C, I> tmp (it);
-- tmp;
return tmp;
}
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_const_iterator1<C, I> operator + (const indexed_const_iterator1<C, I> &it, std::ptrdiff_t n) {
indexed_const_iterator1<C, I> tmp (it);
return tmp += n;
}
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_const_iterator1<C, I> operator + (std::ptrdiff_t n, const indexed_const_iterator1<C, I> &it) {
indexed_const_iterator1<C, I> tmp (it);
return tmp += n;
}
template<class C, class I>
BOOST_UBLAS_INLINE
indexed_const_iterator1<C, I> operator - (const indexed_const_iterator1<C, I> &it, std::ptrdiff_t n) {
indexed_const_iterator1<C, I> tmp (it);
return tmp -= n;
}
#endif
template<class C, class IC>
class indexed_iterator2:
public container_reference<C>,
public random_access_iterator_base<IC,
indexed_iterator2<C, IC>,
typename C::value_type,
typename C::reference> {
public:
typedef C container_type;
typedef IC iterator_category;
typedef typename container_type::size_type size_type;
typedef typename container_type::difference_type difference_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::reference reference;
typedef indexed_iterator1<container_type, iterator_category> dual_iterator_type;
#ifdef BOOST_MSVC_STD_ITERATOR
typedef reverse_iterator_base1<dual_iterator_type, value_type, reference> dual_reverse_iterator_type;
#else
typedef reverse_iterator_base1<dual_iterator_type> dual_reverse_iterator_type;
#endif
// Construction and destruction
BOOST_UBLAS_INLINE
indexed_iterator2 ():
container_reference<container_type> (), it1_ (), it2_ () {}
BOOST_UBLAS_INLINE
indexed_iterator2 (container_type &c, size_type it1, size_type it2):
container_reference<container_type> (c), it1_ (it1), it2_ (it2) {}
// Arithmetic
BOOST_UBLAS_INLINE
indexed_iterator2 &operator ++ () {
++ it2_;
return *this;
}
BOOST_UBLAS_INLINE
indexed_iterator2 &operator -- () {
-- it2_;
return *this;
}
BOOST_UBLAS_INLINE
indexed_iterator2 &operator += (difference_type n) {
it2_ += n;
return *this;
}
BOOST_UBLAS_INLINE
indexed_iterator2 &operator -= (difference_type n) {
it2_ -= n;
return *this;
}
BOOST_UBLAS_INLINE
difference_type operator - (const indexed_iterator2 &it) const {
BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
return it2_ - it.it2_;
}
// Dereference
BOOST_UBLAS_INLINE
reference operator * () const {
BOOST_UBLAS_CHECK (index1 () < (*this) ().size1 (), bad_index ());
BOOST_UBLAS_CHECK (index2 () < (*this) ().size2 (), bad_index ());
return (*this) () (it1_, it2_);
}
BOOST_UBLAS_INLINE
reference operator [] (difference_type n) const {
return *((*this) + n);
}
// Index
BOOST_UBLAS_INLINE
size_type index1 () const {
return it1_;
}
BOOST_UBLAS_INLINE
size_type index2 () const {
return it2_;
}
BOOST_UBLAS_INLINE
dual_iterator_type begin () const {
return (*this) ().find1 (1, 0, index2 ());
}
BOOST_UBLAS_INLINE
dual_iterator_type end () const {
return (*this) ().find1 (1, (*this)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -