28 #ifndef VC_COMMON_ITERATORS_H_ 29 #define VC_COMMON_ITERATORS_H_ 37 #include "elementreference.h" 40 namespace Vc_VERSIONED_NAMESPACE
46 template<
typename _V,
typename Flags>
class MemoryVectorIterator;
48 template <
typename V>
class Iterator;
49 template <
typename V,
bool>
class IteratorBase;
50 template <
typename V>
class IteratorBase<V, true>
53 using iterator_category = std::input_iterator_tag;
54 using value_type =
typename V::value_type;
55 using difference_type = int;
56 using reference = value_type;
57 Vc_ALWAYS_INLINE reference
operator*()
const {
return v()[i()]; }
58 Vc_ALWAYS_INLINE reference operator[](difference_type i2)
const {
return v()[i2]; }
61 Vc_INTRINSIC V &v()
const {
return *
static_cast<const Iterator<V> *
>(
this)->v; }
62 Vc_INTRINSIC difference_type i()
const 64 return static_cast<const Iterator<V> *
>(
this)->i;
68 template <
typename V>
class IteratorBase<V, false>
71 using iterator_category = std::input_iterator_tag;
72 using value_type =
typename V::value_type;
73 using difference_type = int;
74 using reference = Vc::Detail::ElementReference<V, IteratorBase>;
75 Vc_ALWAYS_INLINE reference
operator*()
const {
return {*v(), i()}; }
76 Vc_ALWAYS_INLINE reference operator[](difference_type i2)
const {
return {*v(), i2}; }
79 Vc_INTRINSIC V *v()
const {
return static_cast<const Iterator<V> *
>(
this)->v; }
80 Vc_INTRINSIC difference_type i()
const 82 return static_cast<const Iterator<V> *
>(
this)->i;
86 static Vc_INTRINSIC value_type
get(
const V &o,
int i)
90 template <
typename T>
static Vc_INTRINSIC
void set(V &o,
int i, T &&v)
92 o[i] = std::forward<T>(v);
97 template <
typename V>
class Iterator :
public IteratorBase<V, std::is_const<V>::value>
99 using Base = IteratorBase<V, std::is_const<V>::value>;
103 using typename Base::iterator_category;
104 using typename Base::value_type;
105 using typename Base::difference_type;
106 using pointer =
const Iterator *;
107 using typename Base::reference;
109 constexpr Iterator() =
default;
110 constexpr Iterator(V &_v, difference_type _i) : v(&_v), i(_i) {}
113 Vc_ALWAYS_INLINE pointer operator->()
const {
return this; }
114 using Base::operator*;
116 Vc_ALWAYS_INLINE Iterator &operator++() { ++i;
return *
this; }
117 Vc_ALWAYS_INLINE Iterator operator++(
int) { Iterator tmp = *
this; ++i;
return tmp; }
120 Vc_ALWAYS_INLINE Iterator &operator--() { --i;
return *
this; }
121 Vc_ALWAYS_INLINE Iterator operator--(
int) { Iterator tmp = *
this; --i;
return tmp; }
124 using Base::operator[];
125 Vc_ALWAYS_INLINE Iterator &operator+=(difference_type d) { i += d;
return *
this; }
126 Vc_ALWAYS_INLINE Iterator &operator-=(difference_type d) { i -= d;
return *
this; }
127 Vc_ALWAYS_INLINE Iterator
operator+(difference_type d)
const {
return {*v, i + d}; }
128 Vc_ALWAYS_INLINE Iterator
operator-(difference_type d)
const {
return {*v, i - d}; }
129 Vc_ALWAYS_INLINE difference_type
operator-(
const Iterator &rhs)
const {
return i - rhs.i; }
130 friend Vc_ALWAYS_INLINE Iterator
operator+(difference_type d,
const Iterator &rhs)
132 return {*rhs.v, rhs.i + d};
137 Vc_ALWAYS_INLINE
bool operator==(
const Iterator<V> &rhs)
const {
return v == rhs.v && i == rhs.i; }
138 Vc_ALWAYS_INLINE
bool operator!=(
const Iterator<V> &rhs)
const {
return v == rhs.v && i != rhs.i; }
139 Vc_ALWAYS_INLINE
bool operator< (const Iterator<V> &rhs)
const {
return v == rhs.v && i < rhs.i; }
140 Vc_ALWAYS_INLINE
bool operator<=(const Iterator<V> &rhs)
const {
return v == rhs.v && i <= rhs.i; }
141 Vc_ALWAYS_INLINE
bool operator> (
const Iterator<V> &rhs)
const {
return v == rhs.v && i > rhs.i; }
142 Vc_ALWAYS_INLINE
bool operator>=(
const Iterator<V> &rhs)
const {
return v == rhs.v && i >= rhs.i; }
146 difference_type i = 0;
149 template <
typename V>
using ConstIterator = Iterator<const V>;
151 class BitmaskIterator
164 bit = __builtin_ctzl(mask);
165 #elif defined(Vc_MSVC) 166 _BitScanForward(&bit, mask);
168 #error "Not implemented yet. Please contact vc-devel@compeng.uni-frankfurt.de" 188 BitmaskIterator(decltype(mask) m) : mask(m) { nextBit(); }
189 BitmaskIterator(
const BitmaskIterator &) =
default;
190 BitmaskIterator(BitmaskIterator &&) =
default;
192 Vc_ALWAYS_INLINE
size_t operator->()
const {
return bit; }
193 Vc_ALWAYS_INLINE
size_t operator*()
const {
return bit; }
195 Vc_ALWAYS_INLINE BitmaskIterator &operator++() { resetLsb(); nextBit();
return *
this; }
196 Vc_ALWAYS_INLINE BitmaskIterator operator++(
int) { BitmaskIterator tmp = *
this; resetLsb(); nextBit();
return tmp; }
198 Vc_ALWAYS_INLINE
bool operator==(
const BitmaskIterator &rhs)
const {
return mask == rhs.mask; }
199 Vc_ALWAYS_INLINE
bool operator!=(
const BitmaskIterator &rhs)
const {
return mask != rhs.mask; }
202 template <
typename T>
205 Iterator<typename std::remove_reference<T>::type>>
208 return {std::forward<T>(x), 0};
211 template <
typename T>
214 Iterator<typename std::remove_reference<T>::type>>
217 using TT =
typename std::decay<T>::type;
218 return {std::forward<T>(x),
int(TT::size())};
221 template <
typename T>
222 Vc_ALWAYS_INLINE enable_if<
229 template <
typename T>
230 Vc_ALWAYS_INLINE enable_if<
234 return {v, int(T::size())};
237 template<
typename M> Vc_ALWAYS_INLINE BitmaskIterator begin(
const WhereImpl::WhereMask<M> &w)
239 return w.mask.toInt();
242 template<
typename M> Vc_ALWAYS_INLINE BitmaskIterator end(
const WhereImpl::WhereMask<M> &)
247 template<
typename V,
typename Flags,
typename T> Vc_ALWAYS_INLINE MemoryVectorIterator<V, Flags>
248 makeIterator(T *mem, Flags)
253 template<
typename V,
typename Flags,
typename T> Vc_ALWAYS_INLINE MemoryVectorIterator<const V, Flags>
254 makeIterator(
const T *mem, Flags)
259 template<
typename V,
typename Flags,
typename FlagsX> Vc_ALWAYS_INLINE MemoryVectorIterator<V, Flags>
265 template<
typename V,
typename Flags,
typename FlagsX> Vc_ALWAYS_INLINE MemoryVectorIterator<const V, Flags>
275 using Common::cbegin;
277 using Common::makeIterator;
280 #endif // VC_COMMON_ITERATORS_H_ result_vector_type< L, R > operator-(L &&lhs, R &&rhs)
Applies - component-wise and concurrently.
result_vector_type< L, R >::mask_type operator!=(L &&lhs, R &&rhs)
Applies != component-wise and concurrently.
result_vector_type< L, R > operator*(L &&lhs, R &&rhs)
Applies * component-wise and concurrently.
Identifies any SIMD vector type (independent of implementation or whether it's SimdArray<T, N>).
Helper class for the Memory::vector(size_t) class of functions.
result_vector_type< L, R >::mask_type operator==(L &&lhs, R &&rhs)
Applies == component-wise and concurrently.
result_vector_type< L, R > operator+(L &&lhs, R &&rhs)
Applies + component-wise and concurrently.
result_vector_type< L, R >::mask_type operator>=(L &&lhs, R &&rhs)
Applies >= component-wise and concurrently.
result_vector_type< L, R >::mask_type operator>(L &&lhs, R &&rhs)
Applies > component-wise and concurrently.
Identifies any SIMD mask type (independent of implementation or whether it's SimdMaskArray<T, N>).