10 #ifndef EIGEN_STLITERATORS_H
11 #define EIGEN_STLITERATORS_H
19 template<
typename IteratorType>
20 struct indexed_based_stl_iterator_traits;
22 template<
typename Derived>
23 class indexed_based_stl_iterator_base
26 typedef indexed_based_stl_iterator_traits<Derived> traits;
27 typedef typename traits::XprType XprType;
28 typedef indexed_based_stl_iterator_base<typename traits::non_const_iterator> non_const_iterator;
29 typedef indexed_based_stl_iterator_base<typename traits::const_iterator> const_iterator;
30 typedef std::conditional_t<internal::is_const<XprType>::value,non_const_iterator,const_iterator> other_iterator;
32 friend class indexed_based_stl_iterator_base<typename traits::const_iterator>;
33 friend class indexed_based_stl_iterator_base<typename traits::non_const_iterator>;
35 typedef
Index difference_type;
36 typedef std::random_access_iterator_tag iterator_category;
38 indexed_based_stl_iterator_base()
EIGEN_NO_THROW : mp_xpr(0), m_index(0) {}
39 indexed_based_stl_iterator_base(XprType& xpr,
Index index)
EIGEN_NO_THROW : mp_xpr(&xpr), m_index(index) {}
41 indexed_based_stl_iterator_base(
const non_const_iterator& other)
EIGEN_NO_THROW
42 : mp_xpr(other.mp_xpr), m_index(other.m_index)
45 indexed_based_stl_iterator_base& operator=(
const non_const_iterator& other)
47 mp_xpr = other.mp_xpr;
48 m_index = other.m_index;
52 Derived&
operator++() { ++m_index;
return derived(); }
53 Derived&
operator--() { --m_index;
return derived(); }
58 friend Derived
operator+(
const indexed_based_stl_iterator_base&
a,
Index b) { Derived ret(
a.derived()); ret +=
b;
return ret; }
59 friend Derived
operator-(
const indexed_based_stl_iterator_base&
a,
Index b) { Derived ret(
a.derived()); ret -=
b;
return ret; }
60 friend Derived
operator+(
Index a,
const indexed_based_stl_iterator_base&
b) { Derived ret(
b.derived()); ret +=
a;
return ret; }
61 friend Derived
operator-(
Index a,
const indexed_based_stl_iterator_base&
b) { Derived ret(
b.derived()); ret -=
a;
return ret; }
66 difference_type
operator-(
const indexed_based_stl_iterator_base& other)
const
69 return m_index - other.m_index;
72 difference_type
operator-(
const other_iterator& other)
const
75 return m_index - other.m_index;
78 bool operator==(
const indexed_based_stl_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index == other.m_index; }
79 bool operator!=(
const indexed_based_stl_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index != other.m_index; }
80 bool operator< (
const indexed_based_stl_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index < other.m_index; }
81 bool operator<=(
const indexed_based_stl_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index <= other.m_index; }
82 bool operator> (
const indexed_based_stl_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index > other.m_index; }
83 bool operator>=(
const indexed_based_stl_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index >= other.m_index; }
85 bool operator==(
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index == other.m_index; }
86 bool operator!=(
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index != other.m_index; }
87 bool operator< (
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index < other.m_index; }
88 bool operator<=(
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index <= other.m_index; }
89 bool operator> (
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index > other.m_index; }
90 bool operator>=(
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index >= other.m_index; }
94 Derived& derived() {
return static_cast<Derived&
>(*this); }
95 const Derived& derived()
const {
return static_cast<const Derived&
>(*this); }
101 template<
typename Derived>
102 class indexed_based_stl_reverse_iterator_base
105 typedef indexed_based_stl_iterator_traits<Derived> traits;
106 typedef typename traits::XprType XprType;
107 typedef indexed_based_stl_reverse_iterator_base<typename traits::non_const_iterator> non_const_iterator;
108 typedef indexed_based_stl_reverse_iterator_base<typename traits::const_iterator> const_iterator;
109 typedef std::conditional_t<internal::is_const<XprType>::value,non_const_iterator,const_iterator> other_iterator;
111 friend class indexed_based_stl_reverse_iterator_base<typename traits::const_iterator>;
112 friend class indexed_based_stl_reverse_iterator_base<typename traits::non_const_iterator>;
114 typedef
Index difference_type;
115 typedef std::random_access_iterator_tag iterator_category;
117 indexed_based_stl_reverse_iterator_base() : mp_xpr(0), m_index(0) {}
118 indexed_based_stl_reverse_iterator_base(XprType& xpr,
Index index) : mp_xpr(&xpr), m_index(index) {}
120 indexed_based_stl_reverse_iterator_base(
const non_const_iterator& other)
121 : mp_xpr(other.mp_xpr), m_index(other.m_index)
124 indexed_based_stl_reverse_iterator_base& operator=(
const non_const_iterator& other)
126 mp_xpr = other.mp_xpr;
127 m_index = other.m_index;
131 Derived&
operator++() { --m_index;
return derived(); }
132 Derived&
operator--() { ++m_index;
return derived(); }
137 friend Derived
operator+(
const indexed_based_stl_reverse_iterator_base&
a,
Index b) { Derived ret(
a.derived()); ret +=
b;
return ret; }
138 friend Derived
operator-(
const indexed_based_stl_reverse_iterator_base&
a,
Index b) { Derived ret(
a.derived()); ret -=
b;
return ret; }
139 friend Derived
operator+(
Index a,
const indexed_based_stl_reverse_iterator_base&
b) { Derived ret(
b.derived()); ret +=
a;
return ret; }
140 friend Derived
operator-(
Index a,
const indexed_based_stl_reverse_iterator_base&
b) { Derived ret(
b.derived()); ret -=
a;
return ret; }
145 difference_type
operator-(
const indexed_based_stl_reverse_iterator_base& other)
const
148 return other.m_index - m_index;
151 difference_type
operator-(
const other_iterator& other)
const
154 return other.m_index - m_index;
157 bool operator==(
const indexed_based_stl_reverse_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index == other.m_index; }
158 bool operator!=(
const indexed_based_stl_reverse_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index != other.m_index; }
159 bool operator< (
const indexed_based_stl_reverse_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index > other.m_index; }
160 bool operator<=(
const indexed_based_stl_reverse_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index >= other.m_index; }
161 bool operator> (
const indexed_based_stl_reverse_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index < other.m_index; }
162 bool operator>=(
const indexed_based_stl_reverse_iterator_base& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index <= other.m_index; }
164 bool operator==(
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index == other.m_index; }
165 bool operator!=(
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index != other.m_index; }
166 bool operator< (
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index > other.m_index; }
167 bool operator<=(
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index >= other.m_index; }
168 bool operator> (
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index < other.m_index; }
169 bool operator>=(
const other_iterator& other)
const {
eigen_assert(mp_xpr == other.mp_xpr);
return m_index <= other.m_index; }
173 Derived& derived() {
return static_cast<Derived&
>(*this); }
174 const Derived& derived()
const {
return static_cast<const Derived&
>(*this); }
180 template<
typename XprType>
181 class pointer_based_stl_iterator
183 enum { is_lvalue = internal::is_lvalue<XprType>::value };
184 typedef pointer_based_stl_iterator<std::remove_const_t<XprType>> non_const_iterator;
185 typedef pointer_based_stl_iterator<std::add_const_t<XprType>> const_iterator;
186 typedef std::conditional_t<internal::is_const<XprType>::value,non_const_iterator,const_iterator> other_iterator;
188 friend class pointer_based_stl_iterator<
std::add_const_t<XprType>>;
189 friend class pointer_based_stl_iterator<std::remove_const_t<XprType>>;
191 typedef
Index difference_type;
192 typedef typename XprType::Scalar value_type;
193 typedef std::random_access_iterator_tag iterator_category;
194 typedef std::conditional_t<bool(is_lvalue), value_type*, const value_type*> pointer;
195 typedef std::conditional_t<bool(is_lvalue), value_type&, const value_type&> reference;
199 pointer_based_stl_iterator(XprType& xpr,
Index index)
EIGEN_NO_THROW : m_incr(xpr.innerStride())
201 m_ptr = xpr.data() + index * m_incr.value();
204 pointer_based_stl_iterator(
const non_const_iterator& other)
EIGEN_NO_THROW
205 : m_ptr(other.m_ptr), m_incr(other.m_incr)
208 pointer_based_stl_iterator& operator=(
const non_const_iterator& other)
EIGEN_NO_THROW
211 m_incr.setValue(other.m_incr);
215 reference
operator*()
const {
return *m_ptr; }
216 reference operator[](
Index i)
const {
return *(m_ptr+
i*m_incr.value()); }
217 pointer operator->()
const {
return m_ptr; }
219 pointer_based_stl_iterator&
operator++() { m_ptr += m_incr.
value();
return *
this; }
220 pointer_based_stl_iterator&
operator--() { m_ptr -= m_incr.
value();
return *
this; }
222 pointer_based_stl_iterator
operator++(
int) { pointer_based_stl_iterator prev(*
this);
operator++();
return prev;}
223 pointer_based_stl_iterator
operator--(
int) { pointer_based_stl_iterator prev(*
this);
operator--();
return prev;}
225 friend pointer_based_stl_iterator
operator+(
const pointer_based_stl_iterator&
a,
Index b) { pointer_based_stl_iterator ret(
a); ret +=
b;
return ret; }
226 friend pointer_based_stl_iterator
operator-(
const pointer_based_stl_iterator&
a,
Index b) { pointer_based_stl_iterator ret(
a); ret -=
b;
return ret; }
227 friend pointer_based_stl_iterator
operator+(
Index a,
const pointer_based_stl_iterator&
b) { pointer_based_stl_iterator ret(
b); ret +=
a;
return ret; }
228 friend pointer_based_stl_iterator
operator-(
Index a,
const pointer_based_stl_iterator&
b) { pointer_based_stl_iterator ret(
b); ret -=
a;
return ret; }
230 pointer_based_stl_iterator&
operator+=(
Index b) { m_ptr +=
b*m_incr.value();
return *
this; }
231 pointer_based_stl_iterator&
operator-=(
Index b) { m_ptr -=
b*m_incr.value();
return *
this; }
233 difference_type
operator-(
const pointer_based_stl_iterator& other)
const {
234 return (m_ptr - other.m_ptr)/m_incr.value();
237 difference_type
operator-(
const other_iterator& other)
const {
238 return (m_ptr - other.m_ptr)/m_incr.value();
241 bool operator==(
const pointer_based_stl_iterator& other)
const {
return m_ptr == other.m_ptr; }
242 bool operator!=(
const pointer_based_stl_iterator& other)
const {
return m_ptr != other.m_ptr; }
243 bool operator< (
const pointer_based_stl_iterator& other)
const {
return m_ptr < other.m_ptr; }
244 bool operator<=(
const pointer_based_stl_iterator& other)
const {
return m_ptr <= other.m_ptr; }
245 bool operator> (
const pointer_based_stl_iterator& other)
const {
return m_ptr > other.m_ptr; }
246 bool operator>=(
const pointer_based_stl_iterator& other)
const {
return m_ptr >= other.m_ptr; }
248 bool operator==(
const other_iterator& other)
const {
return m_ptr == other.m_ptr; }
249 bool operator!=(
const other_iterator& other)
const {
return m_ptr != other.m_ptr; }
250 bool operator< (
const other_iterator& other)
const {
return m_ptr < other.m_ptr; }
251 bool operator<=(
const other_iterator& other)
const {
return m_ptr <= other.m_ptr; }
252 bool operator> (
const other_iterator& other)
const {
return m_ptr > other.m_ptr; }
253 bool operator>=(
const other_iterator& other)
const {
return m_ptr >= other.m_ptr; }
258 internal::variable_if_dynamic<Index, XprType::InnerStrideAtCompileTime> m_incr;
261 template<
typename XprType_>
262 struct indexed_based_stl_iterator_traits<generic_randaccess_stl_iterator<XprType_> >
264 typedef XprType_ XprType;
265 typedef generic_randaccess_stl_iterator<std::remove_const_t<XprType>> non_const_iterator;
266 typedef generic_randaccess_stl_iterator<std::add_const_t<XprType>> const_iterator;
269 template<
typename XprType>
270 class generic_randaccess_stl_iterator :
public indexed_based_stl_iterator_base<generic_randaccess_stl_iterator<XprType> >
273 typedef typename XprType::Scalar value_type;
278 has_direct_access = (internal::traits<XprType>::Flags &
DirectAccessBit) ? 1 : 0,
279 is_lvalue = internal::is_lvalue<XprType>::value
282 typedef indexed_based_stl_iterator_base<generic_randaccess_stl_iterator> Base;
289 typedef const value_type read_only_ref_t;
293 typedef std::conditional_t<
bool(is_lvalue), value_type *,
const value_type *> pointer;
294 typedef std::conditional_t<
bool(is_lvalue), value_type&, read_only_ref_t> reference;
296 generic_randaccess_stl_iterator() : Base() {}
297 generic_randaccess_stl_iterator(XprType& xpr,
Index index) : Base(xpr,index) {}
298 generic_randaccess_stl_iterator(
const typename Base::non_const_iterator& other) : Base(other) {}
299 using Base::operator=;
301 reference
operator*()
const {
return (*mp_xpr)(m_index); }
302 reference operator[](
Index i)
const {
return (*mp_xpr)(m_index+
i); }
303 pointer operator->()
const {
return &((*mp_xpr)(m_index)); }
306 template<
typename XprType_, DirectionType Direction>
307 struct indexed_based_stl_iterator_traits<subvector_stl_iterator<XprType_,Direction> >
309 typedef XprType_ XprType;
310 typedef subvector_stl_iterator<std::remove_const_t<XprType>, Direction> non_const_iterator;
311 typedef subvector_stl_iterator<std::add_const_t<XprType>, Direction> const_iterator;
314 template<
typename XprType, DirectionType Direction>
315 class subvector_stl_iterator :
public indexed_based_stl_iterator_base<subvector_stl_iterator<XprType,Direction> >
319 enum { is_lvalue = internal::is_lvalue<XprType>::value };
321 typedef indexed_based_stl_iterator_base<subvector_stl_iterator> Base;
325 typedef std::conditional_t<Direction==Vertical,typename XprType::ColXpr,typename XprType::RowXpr> SubVectorType;
326 typedef std::conditional_t<Direction==Vertical,typename XprType::ConstColXpr,typename XprType::ConstRowXpr> ConstSubVectorType;
330 typedef std::conditional_t<
bool(is_lvalue), SubVectorType, ConstSubVectorType> reference;
331 typedef typename reference::PlainObject value_type;
334 class subvector_stl_iterator_ptr
337 subvector_stl_iterator_ptr(
const reference &subvector) : m_subvector(subvector) {}
338 reference* operator->() {
return &m_subvector; }
340 reference m_subvector;
344 typedef subvector_stl_iterator_ptr pointer;
346 subvector_stl_iterator() : Base() {}
347 subvector_stl_iterator(XprType& xpr,
Index index) : Base(xpr,index) {}
349 reference
operator*()
const {
return (*mp_xpr).template subVector<Direction>(m_index); }
350 reference operator[](
Index i)
const {
return (*mp_xpr).template subVector<Direction>(m_index+
i); }
351 pointer operator->()
const {
return (*mp_xpr).template subVector<Direction>(m_index); }
354 template<
typename XprType_, DirectionType Direction>
355 struct indexed_based_stl_iterator_traits<subvector_stl_reverse_iterator<XprType_,Direction> >
357 typedef XprType_ XprType;
358 typedef subvector_stl_reverse_iterator<std::remove_const_t<XprType>, Direction> non_const_iterator;
359 typedef subvector_stl_reverse_iterator<std::add_const_t<XprType>, Direction> const_iterator;
362 template<
typename XprType, DirectionType Direction>
363 class subvector_stl_reverse_iterator :
public indexed_based_stl_reverse_iterator_base<subvector_stl_reverse_iterator<XprType,Direction> >
367 enum { is_lvalue = internal::is_lvalue<XprType>::value };
369 typedef indexed_based_stl_reverse_iterator_base<subvector_stl_reverse_iterator> Base;
373 typedef std::conditional_t<Direction==Vertical,typename XprType::ColXpr,typename XprType::RowXpr> SubVectorType;
374 typedef std::conditional_t<Direction==Vertical,typename XprType::ConstColXpr,typename XprType::ConstRowXpr> ConstSubVectorType;
378 typedef std::conditional_t<
bool(is_lvalue), SubVectorType, ConstSubVectorType> reference;
379 typedef typename reference::PlainObject value_type;
382 class subvector_stl_reverse_iterator_ptr
385 subvector_stl_reverse_iterator_ptr(
const reference &subvector) : m_subvector(subvector) {}
386 reference* operator->() {
return &m_subvector; }
388 reference m_subvector;
392 typedef subvector_stl_reverse_iterator_ptr pointer;
394 subvector_stl_reverse_iterator() : Base() {}
395 subvector_stl_reverse_iterator(XprType& xpr,
Index index) : Base(xpr,index) {}
397 reference
operator*()
const {
return (*mp_xpr).template subVector<Direction>(m_index); }
398 reference operator[](
Index i)
const {
return (*mp_xpr).template subVector<Direction>(m_index+
i); }
399 pointer operator->()
const {
return (*mp_xpr).template subVector<Direction>(m_index); }
409 template<
typename Derived>
417 template<
typename Derived>
427 template<
typename Derived>
438 template<
typename Derived>
446 template<
typename Derived>
456 template<
typename Derived>
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
random_access_iterator_type const_iterator
const_iterator cbegin() const
const_iterator cend() const
random_access_iterator_type iterator
const unsigned int DirectAccessBit
bool operator==(const bfloat16 &a, const bfloat16 &b)
bool operator>=(const bfloat16 &a, const bfloat16 &b)
bool operator>(const bfloat16 &a, const bfloat16 &b)
bfloat16 operator++(bfloat16 &a)
bfloat16 & operator+=(bfloat16 &a, const bfloat16 &b)
bfloat16 operator--(bfloat16 &a)
bool operator<(const bfloat16 &a, const bfloat16 &b)
bfloat16 & operator-=(bfloat16 &a, const bfloat16 &b)
bool operator<=(const bfloat16 &a, const bfloat16 &b)
bool operator!=(const bfloat16 &a, const bfloat16 &b)
const CwiseBinaryOp< internal::scalar_difference_op< typename DenseDerived::Scalar, typename SparseDerived::Scalar >, const DenseDerived, const SparseDerived > operator-(const MatrixBase< DenseDerived > &a, const SparseMatrixBase< SparseDerived > &b)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
const CwiseBinaryOp< internal::scalar_sum_op< typename DenseDerived::Scalar, typename SparseDerived::Scalar >, const DenseDerived, const SparseDerived > operator+(const MatrixBase< DenseDerived > &a, const SparseMatrixBase< SparseDerived > &b)