Blaze  3.6
UniformIterator.h
Go to the documentation of this file.
1 //=================================================================================================
24 //=================================================================================================
25 
26 #ifndef _BLAZE_MATH_DENSE_UNIFORMITERATOR_H_
27 #define _BLAZE_MATH_DENSE_UNIFORMITERATOR_H_
28 
29 
30 //*************************************************************************************************
31 // Includes
32 //*************************************************************************************************
33 
34 #include <iterator>
35 #include <blaze/math/SIMD.h>
36 #include <blaze/util/Assert.h>
37 #include <blaze/util/MaybeUnused.h>
38 #include <blaze/util/Types.h>
39 
40 
41 namespace blaze {
42 
43 //=================================================================================================
44 //
45 // CLASS DEFINITION
46 //
47 //=================================================================================================
48 
49 //*************************************************************************************************
56 template< typename Type // Type of the elements
57  , bool AF > // Alignment flag
59 {
60  public:
61  //**Type definitions****************************************************************************
62  using IteratorCategory = std::random_access_iterator_tag;
63  using ValueType = Type;
64  using PointerType = Type*;
65  using ReferenceType = Type&;
67 
68  // STL iterator requirements
71  using pointer = PointerType;
74 
77  //**********************************************************************************************
78 
79  //**Constructors********************************************************************************
82  explicit inline constexpr UniformIterator() noexcept;
83  explicit inline constexpr UniformIterator( Type* ptr, size_t index ) noexcept;
84 
85  template< typename Other, bool AF2 >
86  inline constexpr UniformIterator( const UniformIterator<Other,AF2>& it ) noexcept;
87 
88  UniformIterator( const UniformIterator& ) = default;
90  //**********************************************************************************************
91 
92  //**Destructor**********************************************************************************
95  ~UniformIterator() = default;
97  //**********************************************************************************************
98 
99  //**Assignment operators************************************************************************
102  inline constexpr UniformIterator& operator+=( ptrdiff_t inc ) noexcept;
103  inline constexpr UniformIterator& operator-=( ptrdiff_t inc ) noexcept;
104 
105  UniformIterator& operator=( const UniformIterator& ) = default;
107  //**********************************************************************************************
108 
109  //**Increment/decrement operators***************************************************************
112  inline constexpr UniformIterator& operator++() noexcept;
113  inline constexpr const UniformIterator operator++( int ) noexcept;
114  inline constexpr UniformIterator& operator--() noexcept;
115  inline constexpr const UniformIterator operator--( int ) noexcept;
117  //**********************************************************************************************
118 
119  //**Access operators****************************************************************************
122  inline constexpr ReferenceType operator[]( size_t index ) const noexcept;
123  inline constexpr ReferenceType operator* () const noexcept;
124  inline constexpr PointerType operator->() const noexcept;
126  //**********************************************************************************************
127 
128  //**Utility functions***************************************************************************
131  inline constexpr PointerType ptr() const noexcept;
132  inline constexpr size_t idx() const noexcept;
134  //**********************************************************************************************
135 
136  //**Expression template evaluation functions****************************************************
139  inline const SIMDType load () const noexcept;
140  inline const SIMDType loada() const noexcept;
141  inline const SIMDType loadu() const noexcept;
143  //**********************************************************************************************
144 
145  private:
146  //**Member variables****************************************************************************
150  size_t index_;
151 
152  //**********************************************************************************************
153 };
154 //*************************************************************************************************
155 
156 
157 
158 
159 //=================================================================================================
160 //
161 // CONSTRUCTORS
162 //
163 //=================================================================================================
164 
165 //*************************************************************************************************
168 template< typename Type // Type of the elements
169  , bool AF > // Alignment flag
170 inline constexpr UniformIterator<Type,AF>::UniformIterator() noexcept
171  : ptr_ ( nullptr ) // Pointer to the element
172  , index_( 0UL ) // Index of the current element
173 {}
174 //*************************************************************************************************
175 
176 
177 //*************************************************************************************************
183 template< typename Type // Type of the elements
184  , bool AF > // Alignment flag
185 inline constexpr UniformIterator<Type,AF>::UniformIterator( Type* ptr, size_t index ) noexcept
186  : ptr_ ( ptr ) // Pointer to the element
187  , index_( index ) // Index of the current element
188 {}
189 //*************************************************************************************************
190 
191 
192 //*************************************************************************************************
197 template< typename Type // Type of the elements
198  , bool AF > // Alignment flag
199 template< typename Other // Type of the foreign elements
200  , bool AF2 > // Alignment flag of the foreign iterator
202  : ptr_ ( it.ptr() ) // Pointer to the element
203  , index_( it.idx() ) // Index of the current element
204 {}
205 //*************************************************************************************************
206 
207 
208 
209 
210 //=================================================================================================
211 //
212 // ASSIGNMENT OPERATORS
213 //
214 //=================================================================================================
215 
216 //*************************************************************************************************
222 template< typename Type // Type of the elements
223  , bool AF > // Alignment flag
224 inline constexpr UniformIterator<Type,AF>&
226 {
227  index_ += inc;
228  return *this;
229 }
230 //*************************************************************************************************
231 
232 
233 //*************************************************************************************************
239 template< typename Type // Type of the elements
240  , bool AF > // Alignment flag
241 inline constexpr UniformIterator<Type,AF>&
243 {
244  index_ -= dec;
245  return *this;
246 }
247 //*************************************************************************************************
248 
249 
250 
251 
252 //=================================================================================================
253 //
254 // INCREMENT/DECREMENT OPERATORS
255 //
256 //=================================================================================================
257 
258 //*************************************************************************************************
263 template< typename Type // Type of the elements
264  , bool AF > // Alignment flag
265 inline constexpr UniformIterator<Type,AF>&
267 {
268  ++index_;
269  return *this;
270 }
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
279 template< typename Type // Type of the elements
280  , bool AF > // Alignment flag
281 inline constexpr const UniformIterator<Type,AF>
283 {
284  return UniformIterator( ptr_, index_++ );
285 }
286 //*************************************************************************************************
287 
288 
289 //*************************************************************************************************
294 template< typename Type // Type of the elements
295  , bool AF > // Alignment flag
296 inline constexpr UniformIterator<Type,AF>&
298 {
299  --index_;
300  return *this;
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
310 template< typename Type // Type of the elements
311  , bool AF > // Alignment flag
312 inline constexpr const UniformIterator<Type,AF>
314 {
315  return UniformIterator( ptr_, index_-- );
316 }
317 //*************************************************************************************************
318 
319 
320 
321 
322 //=================================================================================================
323 //
324 // ACCESS OPERATORS
325 //
326 //=================================================================================================
327 
328 //*************************************************************************************************
334 template< typename Type // Type of the elements
335  , bool AF > // Alignment flag
336 inline constexpr typename UniformIterator<Type,AF>::ReferenceType
337  UniformIterator<Type,AF>::operator[]( size_t index ) const noexcept
338 {
339  MAYBE_UNUSED( index );
340 
341  return *ptr_;
342 }
343 //*************************************************************************************************
344 
345 
346 //*************************************************************************************************
351 template< typename Type // Type of the elements
352  , bool AF > // Alignment flag
353 inline constexpr typename UniformIterator<Type,AF>::ReferenceType
355 {
356  return *ptr_;
357 }
358 //*************************************************************************************************
359 
360 
361 //*************************************************************************************************
366 template< typename Type // Type of the elements
367  , bool AF > // Alignment flag
368 inline constexpr typename UniformIterator<Type,AF>::PointerType
370 {
371  return ptr_;
372 }
373 //*************************************************************************************************
374 
375 
376 
377 
378 //=================================================================================================
379 //
380 // UTILITY FUNCTIONS
381 //
382 //=================================================================================================
383 
384 //*************************************************************************************************
389 template< typename Type // Type of the elements
390  , bool AF > // Alignment flag
391 inline constexpr typename UniformIterator<Type,AF>::PointerType
393 {
394  return ptr_;
395 }
396 //*************************************************************************************************
397 
398 
399 //*************************************************************************************************
404 template< typename Type // Type of the elements
405  , bool AF > // Alignment flag
406 inline constexpr size_t
408 {
409  return index_;
410 }
411 //*************************************************************************************************
412 
413 
414 
415 
416 
417 //=================================================================================================
418 //
419 // EXPRESSION TEMPLATE EVALUATION FUNCTIONS
420 //
421 //=================================================================================================
422 
423 //*************************************************************************************************
433 template< typename Type // Type of the elements
434  , bool AF > // Alignment flag
435 inline const typename UniformIterator<Type,AF>::SIMDType
437 {
438  if( AF )
439  return loada();
440  else
441  return loadu();
442 }
443 //*************************************************************************************************
444 
445 
446 //*************************************************************************************************
456 template< typename Type // Type of the elements
457  , bool AF > // Alignment flag
458 inline const typename UniformIterator<Type,AF>::SIMDType
460 {
461  return blaze::set( *ptr_ );
462 }
463 //*************************************************************************************************
464 
465 
466 //*************************************************************************************************
476 template< typename Type // Type of the elements
477  , bool AF > // Alignment flag
478 inline const typename UniformIterator<Type,AF>::SIMDType
480 {
481  return blaze::set( *ptr_ );
482 }
483 //*************************************************************************************************
484 
485 
486 
487 
488 //=================================================================================================
489 //
490 // GLOBAL OPERATORS
491 //
492 //=================================================================================================
493 
494 //*************************************************************************************************
497 template< typename T1, bool AF1, typename T2, bool AF2 >
498 constexpr bool
499  operator==( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
500 
501 template< typename T1, bool AF1, typename T2, bool AF2 >
502 constexpr bool
503  operator!=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
504 
505 template< typename T1, bool AF1, typename T2, bool AF2 >
506 constexpr bool
507  operator<( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
508 
509 template< typename T1, bool AF1, typename T2, bool AF2 >
510 constexpr bool
511  operator>( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
512 
513 template< typename T1, bool AF1, typename T2, bool AF2 >
514 constexpr bool
515  operator<=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
516 
517 template< typename T1, bool AF1, typename T2, bool AF2 >
518 constexpr bool
519  operator>=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
520 
521 template< typename Type, bool AF >
522 constexpr const UniformIterator<Type,AF>
523  operator+( const UniformIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
524 
525 template< typename Type, bool AF >
526 constexpr const UniformIterator<Type,AF>
527  operator+( ptrdiff_t inc, const UniformIterator<Type,AF>& it ) noexcept;
528 
529 template< typename Type, bool AF >
530 constexpr const UniformIterator<Type,AF>
531  operator-( const UniformIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
532 
533 template< typename Type, bool AF >
534 constexpr ptrdiff_t
535  operator-( const UniformIterator<Type,AF>& lhs, const UniformIterator<Type,AF>& rhs ) noexcept;
537 //*************************************************************************************************
538 
539 
540 //*************************************************************************************************
547 template< typename T1 // Element type of the left-hand side iterator
548  , bool AF1 // Alignment flag of the left-hand side iterator
549  , typename T2 // Element type of the right-hand side iterator
550  , bool AF2 > // Alignment flag of the right-hand side iterator
551 inline constexpr bool
552  operator==( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept
553 {
554  return lhs.idx() == rhs.idx();
555 }
556 //*************************************************************************************************
557 
558 
559 //*************************************************************************************************
566 template< typename T1 // Element type of the left-hand side iterator
567  , bool AF1 // Alignment flag of the left-hand side iterator
568  , typename T2 // Element type of the right-hand side iterator
569  , bool AF2 > // Alignment flag of the right-hand side iterator
570 inline constexpr bool
571  operator!=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept
572 {
573  return lhs.idx() != rhs.idx();
574 }
575 //*************************************************************************************************
576 
577 
578 //*************************************************************************************************
585 template< typename T1 // Element type of the left-hand side iterator
586  , bool AF1 // Alignment flag of the left-hand side iterator
587  , typename T2 // Element type of the right-hand side iterator
588  , bool AF2 > // Alignment flag of the right-hand side iterator
589 inline constexpr bool
590  operator<( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept
591 {
592  return lhs.idx() == rhs.idx();
593 }
594 //*************************************************************************************************
595 
596 
597 //*************************************************************************************************
604 template< typename T1 // Element type of the left-hand side iterator
605  , bool AF1 // Alignment flag of the left-hand side iterator
606  , typename T2 // Element type of the right-hand side iterator
607  , bool AF2 > // Alignment flag of the right-hand side iterator
608 inline constexpr bool
609  operator>( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept
610 {
611  return lhs.idx() > rhs.idx();
612 }
613 //*************************************************************************************************
614 
615 
616 //*************************************************************************************************
623 template< typename T1 // Element type of the left-hand side iterator
624  , bool AF1 // Alignment flag of the left-hand side iterator
625  , typename T2 // Element type of the right-hand side iterator
626  , bool AF2 > // Alignment flag of the right-hand side iterator
627 inline constexpr bool
628  operator<=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept
629 {
630  return lhs.idx() <= rhs.idx();
631 }
632 //*************************************************************************************************
633 
634 
635 //*************************************************************************************************
642 template< typename T1 // Element type of the left-hand side iterator
643  , bool AF1 // Alignment flag of the left-hand side iterator
644  , typename T2 // Element type of the right-hand side iterator
645  , bool AF2 > // Alignment flag of the right-hand side iterator
646 inline constexpr bool
647  operator>=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept
648 {
649  return lhs.idx() >= rhs.idx();
650 }
651 //*************************************************************************************************
652 
653 
654 //*************************************************************************************************
661 template< typename Type // Element type of the iterator
662  , bool AF > // Alignment flag of the iterator
663 inline constexpr const UniformIterator<Type,AF>
664  operator+( const UniformIterator<Type,AF>& it, ptrdiff_t inc ) noexcept
665 {
666  return UniformIterator<Type,AF>( it.ptr(), it.idx() + inc );
667 }
668 //*************************************************************************************************
669 
670 
671 //*************************************************************************************************
678 template< typename Type // Element type of the iterator
679  , bool AF > // Alignment flag of the iterator
680 inline constexpr const UniformIterator<Type,AF>
681  operator+( ptrdiff_t inc, const UniformIterator<Type,AF>& it ) noexcept
682 {
683  return UniformIterator<Type,AF>( it.ptr(), it.idx() + inc );
684 }
685 //*************************************************************************************************
686 
687 
688 //*************************************************************************************************
695 template< typename Type // Element type of the iterator
696  , bool AF > // Alignment flag of the iterator
697 inline constexpr const UniformIterator<Type,AF>
698  operator-( const UniformIterator<Type,AF>& it, ptrdiff_t dec ) noexcept
699 {
700  return UniformIterator<Type,AF>( it.ptr(), it.idx() - dec );
701 }
702 //*************************************************************************************************
703 
704 
705 //*************************************************************************************************
712 template< typename Type // Element type of the iterator
713  , bool AF > // Alignment flag of the iterator
714 inline constexpr ptrdiff_t
716 {
717  return lhs.idx() - rhs.idx();
718 }
719 //*************************************************************************************************
720 
721 } // namespace blaze
722 
723 #endif
Pointer difference type of the Blaze library.
Header file for basic type definitions.
constexpr const DenseIterator< Type, AF > operator-(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Subtraction between a DenseIterator and an integral value.
Definition: DenseIterator.h:750
IteratorCategory iterator_category
The iterator category.
Definition: UniformIterator.h:69
constexpr UniformIterator & operator-=(ptrdiff_t inc) noexcept
Subtraction assignment operator.
Definition: UniformIterator.h:242
constexpr bool operator<(const NegativeAccuracy< A > &lhs, const T &rhs)
Less-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:332
ValueType value_type
Type of the underlying elements.
Definition: UniformIterator.h:70
const SIMDType loada() const noexcept
Aligned load of the SIMD element at the current iterator position.
Definition: UniformIterator.h:459
constexpr UniformIterator & operator+=(ptrdiff_t inc) noexcept
Addition assignment operator.
Definition: UniformIterator.h:225
const SIMDType load() const noexcept
Load of the SIMD element at the current iterator position.
Definition: UniformIterator.h:436
typename SIMDTrait< T >::Type SIMDTrait_t
Auxiliary alias declaration for the SIMDTrait class template.The SIMDTrait_t alias declaration provid...
Definition: SIMDTrait.h:315
Header file for the MAYBE_UNUSED function template.
constexpr ReferenceType operator *() const noexcept
Direct access to the element at the current iterator position.
Definition: UniformIterator.h:354
SIMDTrait_t< Type > SIMDType
SIMD type of the elements.
Definition: UniformIterator.h:76
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Type * PointerType
Pointer return type.
Definition: UniformIterator.h:64
constexpr size_t idx() const noexcept
Low-level access to the underlying index of the iterator.
Definition: UniformIterator.h:407
constexpr UniformIterator & operator++() noexcept
Pre-increment operator.
Definition: UniformIterator.h:266
constexpr bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:370
constexpr bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:446
Type & ReferenceType
Reference return type.
Definition: UniformIterator.h:65
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
Header file for all SIMD functionality.
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
constexpr UniformIterator & operator--() noexcept
Pre-decrement operator.
Definition: UniformIterator.h:297
PointerType ptr_
Pointer to the element.
Definition: UniformIterator.h:149
Type ValueType
Type of the underlying elements.
Definition: UniformIterator.h:63
PointerType pointer
Pointer return type.
Definition: UniformIterator.h:71
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: UniformIterator.h:62
Header file for run time assertion macros.
BLAZE_ALWAYS_INLINE const EnableIf_t< IsIntegral_v< T > &&HasSize_v< T, 1UL >, If_t< IsSigned_v< T >, SIMDint8, SIMDuint8 > > set(T value) noexcept
Sets all values in the vector to the given 1-byte integral value.
Definition: Set.h:75
constexpr bool operator<=(const NegativeAccuracy< A > &, const T &rhs)
Less-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:408
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: UniformIterator.h:66
constexpr const DenseIterator< Type, AF > operator+(const DenseIterator< Type, AF > &it, ptrdiff_t inc) noexcept
Addition between a DenseIterator and an integral value.
Definition: DenseIterator.h:718
Implementation of a generic iterator for uniform vectors and matrices.The UniformIterator represents ...
Definition: UniformIterator.h:58
const SIMDType loadu() const noexcept
Unaligned load of the SIMD element at the current iterator position.
Definition: UniformIterator.h:479
constexpr ReferenceType operator[](size_t index) const noexcept
Direct access to the underlying elements.
Definition: UniformIterator.h:337
constexpr UniformIterator() noexcept
Default constructor for the UniformIterator class.
Definition: UniformIterator.h:170
constexpr PointerType operator->() const noexcept
Direct access to the element at the current iterator position.
Definition: UniformIterator.h:369
ReferenceType reference
Reference return type.
Definition: UniformIterator.h:72
constexpr PointerType ptr() const noexcept
Low-level access to the current memory location of the iterator.
Definition: UniformIterator.h:392
size_t index_
Index of the current element.
Definition: UniformIterator.h:150