Blaze 3.9
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>
36#include <blaze/math/SIMD.h>
37#include <blaze/util/Assert.h>
39#include <blaze/util/Types.h>
40
41
42namespace blaze {
43
44//=================================================================================================
45//
46// CLASS DEFINITION
47//
48//=================================================================================================
49
50//*************************************************************************************************
57template< typename Type // Type of the elements
58 , AlignmentFlag AF > // Alignment flag
60{
61 public:
62 //**Type definitions****************************************************************************
63 using IteratorCategory = std::random_access_iterator_tag;
64 using ValueType = Type;
65 using PointerType = Type*;
66 using ReferenceType = Type&;
67 using DifferenceType = ptrdiff_t;
68
69 // STL iterator requirements
75
78 //**********************************************************************************************
79
80 //**Constructors********************************************************************************
83 explicit constexpr UniformIterator() noexcept;
84 explicit constexpr UniformIterator( Type* ptr, size_t index ) noexcept;
85
86 template< typename Other, AlignmentFlag AF2 >
87 constexpr UniformIterator( const UniformIterator<Other,AF2>& it ) noexcept;
88
89 UniformIterator( const UniformIterator& ) = default;
91 //**********************************************************************************************
92
93 //**Destructor**********************************************************************************
96 ~UniformIterator() = default;
98 //**********************************************************************************************
99
100 //**Assignment operators************************************************************************
103 constexpr UniformIterator& operator+=( ptrdiff_t inc ) noexcept;
104 constexpr UniformIterator& operator-=( ptrdiff_t inc ) noexcept;
105
106 UniformIterator& operator=( const UniformIterator& ) = default;
108 //**********************************************************************************************
109
110 //**Increment/decrement operators***************************************************************
113 constexpr UniformIterator& operator++() noexcept;
114 constexpr const UniformIterator operator++( int ) noexcept;
115 constexpr UniformIterator& operator--() noexcept;
116 constexpr const UniformIterator operator--( int ) noexcept;
118 //**********************************************************************************************
119
120 //**Access operators****************************************************************************
123 constexpr ReferenceType operator[]( size_t index ) const noexcept;
124 constexpr ReferenceType operator* () const noexcept;
125 constexpr PointerType operator->() const noexcept;
127 //**********************************************************************************************
128
129 //**Utility functions***************************************************************************
132 constexpr PointerType ptr() const noexcept;
133 constexpr size_t idx() const noexcept;
135 //**********************************************************************************************
136
137 //**Expression template evaluation functions****************************************************
140 inline const SIMDType load () const noexcept;
141 inline const SIMDType loada() const noexcept;
142 inline const SIMDType loadu() const noexcept;
144 //**********************************************************************************************
145
146 private:
147 //**Member variables****************************************************************************
151 size_t index_;
153 //**********************************************************************************************
154};
155//*************************************************************************************************
156
157
158
159
160//=================================================================================================
161//
162// CONSTRUCTORS
163//
164//=================================================================================================
165
166//*************************************************************************************************
169template< typename Type // Type of the elements
170 , AlignmentFlag AF > // Alignment flag
171constexpr UniformIterator<Type,AF>::UniformIterator() noexcept
172 : ptr_ ( nullptr ) // Pointer to the element
173 , index_( 0UL ) // Index of the current element
174{}
175//*************************************************************************************************
176
177
178//*************************************************************************************************
184template< typename Type // Type of the elements
185 , AlignmentFlag AF > // Alignment flag
186constexpr UniformIterator<Type,AF>::UniformIterator( Type* ptr, size_t index ) noexcept
187 : ptr_ ( ptr ) // Pointer to the element
188 , index_( index ) // Index of the current element
189{}
190//*************************************************************************************************
191
192
193//*************************************************************************************************
198template< typename Type // Type of the elements
199 , AlignmentFlag AF > // Alignment flag
200template< typename Other // Type of the foreign elements
201 , AlignmentFlag AF2 > // Alignment flag of the foreign iterator
203 : ptr_ ( it.ptr() ) // Pointer to the element
204 , index_( it.idx() ) // Index of the current element
205{}
206//*************************************************************************************************
207
208
209
210
211//=================================================================================================
212//
213// ASSIGNMENT OPERATORS
214//
215//=================================================================================================
216
217//*************************************************************************************************
223template< typename Type // Type of the elements
224 , AlignmentFlag AF > // Alignment flag
226 UniformIterator<Type,AF>::operator+=( ptrdiff_t inc ) noexcept
227{
228 index_ += inc;
229 return *this;
230}
231//*************************************************************************************************
232
233
234//*************************************************************************************************
240template< typename Type // Type of the elements
241 , AlignmentFlag AF > // Alignment flag
243 UniformIterator<Type,AF>::operator-=( ptrdiff_t dec ) noexcept
244{
245 index_ -= dec;
246 return *this;
247}
248//*************************************************************************************************
249
250
251
252
253//=================================================================================================
254//
255// INCREMENT/DECREMENT OPERATORS
256//
257//=================================================================================================
258
259//*************************************************************************************************
264template< typename Type // Type of the elements
265 , AlignmentFlag AF > // Alignment flag
268{
269 ++index_;
270 return *this;
271}
272//*************************************************************************************************
273
274
275//*************************************************************************************************
280template< typename Type // Type of the elements
281 , AlignmentFlag AF > // Alignment flag
282constexpr const UniformIterator<Type,AF>
284{
285 return UniformIterator( ptr_, index_++ );
286}
287//*************************************************************************************************
288
289
290//*************************************************************************************************
295template< typename Type // Type of the elements
296 , AlignmentFlag AF > // Alignment flag
299{
300 --index_;
301 return *this;
302}
303//*************************************************************************************************
304
305
306//*************************************************************************************************
311template< typename Type // Type of the elements
312 , AlignmentFlag AF > // Alignment flag
313constexpr const UniformIterator<Type,AF>
315{
316 return UniformIterator( ptr_, index_-- );
317}
318//*************************************************************************************************
319
320
321
322
323//=================================================================================================
324//
325// ACCESS OPERATORS
326//
327//=================================================================================================
328
329//*************************************************************************************************
335template< typename Type // Type of the elements
336 , AlignmentFlag AF > // Alignment flag
338 UniformIterator<Type,AF>::operator[]( size_t index ) const noexcept
339{
340 MAYBE_UNUSED( index );
341
342 return *ptr_;
343}
344//*************************************************************************************************
345
346
347//*************************************************************************************************
352template< typename Type // Type of the elements
353 , AlignmentFlag AF > // Alignment flag
356{
357 return *ptr_;
358}
359//*************************************************************************************************
360
361
362//*************************************************************************************************
367template< typename Type // Type of the elements
368 , AlignmentFlag AF > // Alignment flag
371{
372 return ptr_;
373}
374//*************************************************************************************************
375
376
377
378
379//=================================================================================================
380//
381// UTILITY FUNCTIONS
382//
383//=================================================================================================
384
385//*************************************************************************************************
390template< typename Type // Type of the elements
391 , AlignmentFlag AF > // Alignment flag
394{
395 return ptr_;
396}
397//*************************************************************************************************
398
399
400//*************************************************************************************************
405template< typename Type // Type of the elements
406 , AlignmentFlag AF > // Alignment flag
407constexpr size_t
409{
410 return index_;
411}
412//*************************************************************************************************
413
414
415
416
417
418//=================================================================================================
419//
420// EXPRESSION TEMPLATE EVALUATION FUNCTIONS
421//
422//=================================================================================================
423
424//*************************************************************************************************
434template< typename Type // Type of the elements
435 , AlignmentFlag AF > // Alignment flag
436inline const typename UniformIterator<Type,AF>::SIMDType
438{
439 if( AF )
440 return loada();
441 else
442 return loadu();
443}
444//*************************************************************************************************
445
446
447//*************************************************************************************************
457template< typename Type // Type of the elements
458 , AlignmentFlag AF > // Alignment flag
459inline const typename UniformIterator<Type,AF>::SIMDType
461{
462 return blaze::set( *ptr_ );
463}
464//*************************************************************************************************
465
466
467//*************************************************************************************************
477template< typename Type // Type of the elements
478 , AlignmentFlag AF > // Alignment flag
479inline const typename UniformIterator<Type,AF>::SIMDType
481{
482 return blaze::set( *ptr_ );
483}
484//*************************************************************************************************
485
486
487
488
489//=================================================================================================
490//
491// GLOBAL OPERATORS
492//
493//=================================================================================================
494
495//*************************************************************************************************
498template< typename T1, AlignmentFlag AF1, typename T2, AlignmentFlag AF2 >
499constexpr bool
500 operator==( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
501
502template< typename T1, AlignmentFlag AF1, typename T2, AlignmentFlag AF2 >
503constexpr bool
504 operator!=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
505
506template< typename T1, AlignmentFlag AF1, typename T2, AlignmentFlag AF2 >
507constexpr bool
508 operator<( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
509
510template< typename T1, AlignmentFlag AF1, typename T2, AlignmentFlag AF2 >
511constexpr bool
512 operator>( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
513
514template< typename T1, AlignmentFlag AF1, typename T2, AlignmentFlag AF2 >
515constexpr bool
516 operator<=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
517
518template< typename T1, AlignmentFlag AF1, typename T2, AlignmentFlag AF2 >
519constexpr bool
520 operator>=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept;
521
522template< typename Type, AlignmentFlag AF >
523constexpr const UniformIterator<Type,AF>
524 operator+( const UniformIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
525
526template< typename Type, AlignmentFlag AF >
527constexpr const UniformIterator<Type,AF>
528 operator+( ptrdiff_t inc, const UniformIterator<Type,AF>& it ) noexcept;
529
530template< typename Type, AlignmentFlag AF >
531constexpr const UniformIterator<Type,AF>
532 operator-( const UniformIterator<Type,AF>& it, ptrdiff_t inc ) noexcept;
533
534template< typename Type, AlignmentFlag AF >
535constexpr ptrdiff_t
536 operator-( const UniformIterator<Type,AF>& lhs, const UniformIterator<Type,AF>& rhs ) noexcept;
538//*************************************************************************************************
539
540
541//*************************************************************************************************
548template< typename T1 // Element type of the left-hand side iterator
549 , AlignmentFlag AF1 // Alignment flag of the left-hand side iterator
550 , typename T2 // Element type of the right-hand side iterator
551 , AlignmentFlag AF2 > // Alignment flag of the right-hand side iterator
552constexpr bool
554{
555 return lhs.idx() == rhs.idx();
556}
557//*************************************************************************************************
558
559
560//*************************************************************************************************
567template< typename T1 // Element type of the left-hand side iterator
568 , AlignmentFlag AF1 // Alignment flag of the left-hand side iterator
569 , typename T2 // Element type of the right-hand side iterator
570 , AlignmentFlag AF2 > // Alignment flag of the right-hand side iterator
571constexpr bool
573{
574 return lhs.idx() != rhs.idx();
575}
576//*************************************************************************************************
577
578
579//*************************************************************************************************
586template< typename T1 // Element type of the left-hand side iterator
587 , AlignmentFlag AF1 // Alignment flag of the left-hand side iterator
588 , typename T2 // Element type of the right-hand side iterator
589 , AlignmentFlag AF2 > // Alignment flag of the right-hand side iterator
590constexpr bool
591 operator<( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept
592{
593 return lhs.idx() == rhs.idx();
594}
595//*************************************************************************************************
596
597
598//*************************************************************************************************
605template< typename T1 // Element type of the left-hand side iterator
606 , AlignmentFlag AF1 // Alignment flag of the left-hand side iterator
607 , typename T2 // Element type of the right-hand side iterator
608 , AlignmentFlag AF2 > // Alignment flag of the right-hand side iterator
609constexpr bool
611{
612 return lhs.idx() > rhs.idx();
613}
614//*************************************************************************************************
615
616
617//*************************************************************************************************
624template< typename T1 // Element type of the left-hand side iterator
625 , AlignmentFlag AF1 // Alignment flag of the left-hand side iterator
626 , typename T2 // Element type of the right-hand side iterator
627 , AlignmentFlag AF2 > // Alignment flag of the right-hand side iterator
628constexpr bool
629 operator<=( const UniformIterator<T1,AF1>& lhs, const UniformIterator<T2,AF2>& rhs ) noexcept
630{
631 return lhs.idx() <= rhs.idx();
632}
633//*************************************************************************************************
634
635
636//*************************************************************************************************
643template< typename T1 // Element type of the left-hand side iterator
644 , AlignmentFlag AF1 // Alignment flag of the left-hand side iterator
645 , typename T2 // Element type of the right-hand side iterator
646 , AlignmentFlag AF2 > // Alignment flag of the right-hand side iterator
647constexpr bool
649{
650 return lhs.idx() >= rhs.idx();
651}
652//*************************************************************************************************
653
654
655//*************************************************************************************************
662template< typename Type // Element type of the iterator
663 , AlignmentFlag AF > // Alignment flag of the iterator
664constexpr const UniformIterator<Type,AF>
665 operator+( const UniformIterator<Type,AF>& it, ptrdiff_t inc ) noexcept
666{
667 return UniformIterator<Type,AF>( it.ptr(), it.idx() + inc );
668}
669//*************************************************************************************************
670
671
672//*************************************************************************************************
679template< typename Type // Element type of the iterator
680 , AlignmentFlag AF > // Alignment flag of the iterator
681constexpr const UniformIterator<Type,AF>
682 operator+( ptrdiff_t inc, const UniformIterator<Type,AF>& it ) noexcept
683{
684 return UniformIterator<Type,AF>( it.ptr(), it.idx() + inc );
685}
686//*************************************************************************************************
687
688
689//*************************************************************************************************
696template< typename Type // Element type of the iterator
697 , AlignmentFlag AF > // Alignment flag of the iterator
698constexpr const UniformIterator<Type,AF>
699 operator-( const UniformIterator<Type,AF>& it, ptrdiff_t dec ) noexcept
700{
701 return UniformIterator<Type,AF>( it.ptr(), it.idx() - dec );
702}
703//*************************************************************************************************
704
705
706//*************************************************************************************************
713template< typename Type // Element type of the iterator
714 , AlignmentFlag AF > // Alignment flag of the iterator
715constexpr ptrdiff_t
717{
718 return lhs.idx() - rhs.idx();
719}
720//*************************************************************************************************
721
722} // namespace blaze
723
724#endif
Header file for the alignment flag enumeration.
Header file for run time assertion macros.
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:751
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:719
Header file for the MAYBE_UNUSED function template.
Header file for all SIMD functionality.
Implementation of a generic iterator for uniform vectors and matrices.
Definition: UniformIterator.h:60
PointerType ptr_
Pointer to the element.
Definition: UniformIterator.h:150
IteratorCategory iterator_category
The iterator category.
Definition: UniformIterator.h:70
const SIMDType loadu() const noexcept
Unaligned load of the SIMD element at the current iterator position.
Definition: UniformIterator.h:480
Type & ReferenceType
Reference return type.
Definition: UniformIterator.h:66
constexpr PointerType operator->() const noexcept
Direct access to the element at the current iterator position.
Definition: UniformIterator.h:370
constexpr size_t idx() const noexcept
Low-level access to the underlying index of the iterator.
Definition: UniformIterator.h:408
constexpr ReferenceType operator*() const noexcept
Direct access to the element at the current iterator position.
Definition: UniformIterator.h:355
DifferenceType difference_type
Difference between two iterators.
Definition: UniformIterator.h:74
const SIMDType loada() const noexcept
Aligned load of the SIMD element at the current iterator position.
Definition: UniformIterator.h:460
size_t index_
Index of the current element.
Definition: UniformIterator.h:151
const SIMDType load() const noexcept
Load of the SIMD element at the current iterator position.
Definition: UniformIterator.h:437
constexpr UniformIterator & operator-=(ptrdiff_t inc) noexcept
Subtraction assignment operator.
Definition: UniformIterator.h:243
constexpr UniformIterator & operator+=(ptrdiff_t inc) noexcept
Addition assignment operator.
Definition: UniformIterator.h:226
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: UniformIterator.h:63
SIMDTrait_t< Type > SIMDType
SIMD type of the elements.
Definition: UniformIterator.h:77
constexpr UniformIterator & operator++() noexcept
Pre-increment operator.
Definition: UniformIterator.h:267
Type ValueType
Type of the underlying elements.
Definition: UniformIterator.h:64
constexpr PointerType ptr() const noexcept
Low-level access to the current memory location of the iterator.
Definition: UniformIterator.h:393
constexpr ReferenceType operator[](size_t index) const noexcept
Direct access to the underlying elements.
Definition: UniformIterator.h:338
ValueType value_type
Type of the underlying elements.
Definition: UniformIterator.h:71
constexpr UniformIterator() noexcept
Default constructor for the UniformIterator class.
Definition: UniformIterator.h:171
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: UniformIterator.h:67
Type * PointerType
Pointer return type.
Definition: UniformIterator.h:65
ReferenceType reference
Reference return type.
Definition: UniformIterator.h:73
PointerType pointer
Pointer return type.
Definition: UniformIterator.h:72
constexpr UniformIterator & operator--() noexcept
Pre-decrement operator.
Definition: UniformIterator.h:298
Pointer difference type of the Blaze library.
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 > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
AlignmentFlag
Alignment flag for (un-)aligned vectors and matrices.
Definition: AlignmentFlag.h:63
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
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
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 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
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
typename SIMDTrait< T >::Type SIMDTrait_t
Auxiliary alias declaration for the SIMDTrait class template.
Definition: SIMDTrait.h:315
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
Header file for basic type definitions.