Blaze 3.9
InitializerIterator.h
Go to the documentation of this file.
1//=================================================================================================
24//=================================================================================================
25
26#ifndef _BLAZE_MATH_DENSE_INITIALIZERITERATOR_H_
27#define _BLAZE_MATH_DENSE_INITIALIZERITERATOR_H_
28
29
30//*************************************************************************************************
31// Includes
32//*************************************************************************************************
33
34#include <iterator>
36#include <blaze/util/Types.h>
37
38
39namespace blaze {
40
41//=================================================================================================
42//
43// CLASS DEFINITION
44//
45//=================================================================================================
46
47//*************************************************************************************************
55template< typename Type > // Type of the elements
57{
58 public:
59 //**Type definitions****************************************************************************
60 using IteratorCategory = std::random_access_iterator_tag;
61 using ValueType = Type;
62 using PointerType = const Type*;
63 using ReferenceType = const Type&;
64 using DifferenceType = ptrdiff_t;
65
66 // STL iterator requirements
72 //**********************************************************************************************
73
74 //**Constructors********************************************************************************
77 explicit inline InitializerIterator() noexcept;
78 explicit inline InitializerIterator( size_t index, initializer_list<Type> list ) noexcept;
79
80 InitializerIterator( const InitializerIterator& ) = default;
82 //**********************************************************************************************
83
84 //**Destructor**********************************************************************************
87 ~InitializerIterator() = default;
89 //**********************************************************************************************
90
91 //**Assignment operators************************************************************************
94 inline InitializerIterator& operator+=( ptrdiff_t inc ) noexcept;
95 inline InitializerIterator& operator-=( ptrdiff_t dec ) noexcept;
96
97 InitializerIterator& operator=( const InitializerIterator& ) = default;
99 //**********************************************************************************************
100
101 //**Increment/decrement operators***************************************************************
104 inline InitializerIterator& operator++() noexcept;
105 inline const InitializerIterator operator++( int ) noexcept;
106 inline InitializerIterator& operator--() noexcept;
107 inline const InitializerIterator operator--( int ) noexcept;
109 //**********************************************************************************************
110
111 //**Access operators****************************************************************************
114 inline ReferenceType operator[]( size_t index ) const noexcept;
115 inline ReferenceType operator* () const noexcept;
116 inline PointerType operator->() const noexcept;
118 //**********************************************************************************************
119
120 //**Utility functions***************************************************************************
123 inline size_t index() const noexcept;
124 inline initializer_list<Type> list () const noexcept;
126 //**********************************************************************************************
127
128 private:
129 //**Member variables****************************************************************************
130 size_t index_;
131 initializer_list<Type> list_;
132
133 static const Type zero_;
134 //**********************************************************************************************
135};
136//*************************************************************************************************
137
138
139
140
141//=================================================================================================
142//
143// DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
144//
145//=================================================================================================
146
147template< typename Type > // Type of the elements
148const Type InitializerIterator<Type>::zero_{};
149
150
151
152
153//=================================================================================================
154//
155// CONSTRUCTORS
156//
157//=================================================================================================
158
159//*************************************************************************************************
162template< typename Type > // Type of the elements
164 : index_() // Current index of the iterator within the initializer list
165 , list_ () // The initializer list to be traversed
166{}
167//*************************************************************************************************
168
169
170//*************************************************************************************************
176template< typename Type > // Type of the elements
177inline InitializerIterator<Type>::InitializerIterator( size_t index, initializer_list<Type> list ) noexcept
178 : index_( index ) // Current index of the iterator within the initializer list
179 , list_ ( list ) // The initializer list to be traversed
180{}
181//*************************************************************************************************
182
183
184
185
186//=================================================================================================
187//
188// ASSIGNMENT OPERATORS
189//
190//=================================================================================================
191
192//*************************************************************************************************
198template< typename Type > // Type of the elements
200{
201 index_ += inc;
202 return *this;
203}
204//*************************************************************************************************
205
206
207//*************************************************************************************************
213template< typename Type > // Type of the elements
215{
216 index_ -= dec;
217 return *this;
218}
219//*************************************************************************************************
220
221
222
223
224//=================================================================================================
225//
226// INCREMENT/DECREMENT OPERATORS
227//
228//=================================================================================================
229
230//*************************************************************************************************
235template< typename Type > // Type of the elements
237{
238 ++index_;
239 return *this;
240}
241//*************************************************************************************************
242
243
244//*************************************************************************************************
249template< typename Type > // Type of the elements
251{
252 return InitializerIterator( index_++, list_ );
253}
254//*************************************************************************************************
255
256
257//*************************************************************************************************
262template< typename Type > // Type of the elements
264{
265 --index_;
266 return *this;
267}
268//*************************************************************************************************
269
270
271//*************************************************************************************************
276template< typename Type > // Type of the elements
278{
279 return InitializerIterator( index_--, list_ );
280}
281//*************************************************************************************************
282
283
284
285
286//=================================================================================================
287//
288// ACCESS OPERATORS
289//
290//=================================================================================================
291
292//*************************************************************************************************
298template< typename Type > // Type of the elements
301{
302 if( index < list_.size() )
303 return list_.begin()[index];
304 else
305 return zero_;
306}
307//*************************************************************************************************
308
309
310//*************************************************************************************************
315template< typename Type > // Type of the elements
318{
319 if( index_ < list_.size() )
320 return list_.begin()[index_];
321 else
322 return zero_;
323}
324//*************************************************************************************************
325
326
327//*************************************************************************************************
332template< typename Type > // Type of the elements
335{
336 if( index_ < list_.size() )
337 return list_.begin() + index_;
338 else
339 return &zero_;
340}
341//*************************************************************************************************
342
343
344
345
346//=================================================================================================
347//
348// UTILITY FUNCTIONS
349//
350//=================================================================================================
351
352//*************************************************************************************************
357template< typename Type > // Type of the elements
358inline size_t InitializerIterator<Type>::index() const noexcept
359{
360 return index_;
361}
362//*************************************************************************************************
363
364
365//*************************************************************************************************
370template< typename Type > // Type of the elements
371inline initializer_list<Type> InitializerIterator<Type>::list() const noexcept
372{
373 return list_;
374}
375//*************************************************************************************************
376
377
378
379
380//=================================================================================================
381//
382// GLOBAL OPERATORS
383//
384//=================================================================================================
385
386//*************************************************************************************************
389template< typename Type >
390bool operator==( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
391
392template< typename Type >
393bool operator!=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
394
395template< typename Type >
396bool operator<( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
397
398template< typename Type >
399bool operator>( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
400
401template< typename Type >
402bool operator<=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
403
404template< typename Type >
405bool operator>=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
406
407template< typename Type >
408const InitializerIterator<Type> operator+( const InitializerIterator<Type>& it, ptrdiff_t inc ) noexcept;
409
410template< typename Type >
411const InitializerIterator<Type> operator+( ptrdiff_t inc, const InitializerIterator<Type>& it ) noexcept;
412
413template< typename Type >
414const InitializerIterator<Type> operator-( const InitializerIterator<Type>& it, ptrdiff_t dec ) noexcept;
415
416template< typename Type >
417ptrdiff_t operator-( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
419//*************************************************************************************************
420
421
422//*************************************************************************************************
429template< typename Type > // Type of the elements
430inline bool operator==( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
431{
432 return lhs.index() == rhs.index();
433}
434//*************************************************************************************************
435
436
437//*************************************************************************************************
444template< typename Type > // Type of the elements
445inline bool operator!=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
446{
447 return lhs.index() != rhs.index();
448}
449//*************************************************************************************************
450
451
452//*************************************************************************************************
459template< typename Type > // Type of the elements
460inline bool operator<( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
461{
462 return lhs.index() < rhs.index();
463}
464//*************************************************************************************************
465
466
467//*************************************************************************************************
474template< typename Type > // Type of the elements
475inline bool operator>( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
476{
477 return lhs.index() > rhs.index();
478}
479//*************************************************************************************************
480
481
482//*************************************************************************************************
489template< typename Type > // Type of the elements
490inline bool operator<=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
491{
492 return lhs.index() <= rhs.index();
493}
494//*************************************************************************************************
495
496
497//*************************************************************************************************
504template< typename Type > // Type of the elements
505inline bool operator>=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
506{
507 return lhs.index() >= rhs.index();
508}
509//*************************************************************************************************
510
511
512//*************************************************************************************************
519template< typename Type > // Type of the elements
520inline const InitializerIterator<Type> operator+( const InitializerIterator<Type>& it, ptrdiff_t inc ) noexcept
521{
522 return InitializerIterator<Type>( it.index() + inc, it.list() );
523}
524//*************************************************************************************************
525
526
527//*************************************************************************************************
534template< typename Type > // Type of the elements
535inline const InitializerIterator<Type> operator+( ptrdiff_t inc, const InitializerIterator<Type>& it ) noexcept
536{
537 return InitializerIterator<Type>( it.index() + inc, it.list() );
538}
539//*************************************************************************************************
540
541
542//*************************************************************************************************
549template< typename Type > // Type of the elements
550inline const InitializerIterator<Type> operator-( const InitializerIterator<Type>& it, ptrdiff_t dec ) noexcept
551{
552 return InitializerIterator<Type>( it.index() - dec, it.list() );
553}
554//*************************************************************************************************
555
556
557//*************************************************************************************************
564template< typename Type > // Type of the elements
565inline ptrdiff_t operator-( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
566{
567 return lhs.index() - rhs.index();
568}
569//*************************************************************************************************
570
571} // namespace blaze
572
573#endif
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
Implementation of an iterator for (extended) initializer lists.
Definition: InitializerIterator.h:57
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: InitializerIterator.h:64
size_t index_
Current index of the iterator within the initializer list.
Definition: InitializerIterator.h:130
const Type * PointerType
Pointer return type.
Definition: InitializerIterator.h:62
InitializerIterator & operator+=(ptrdiff_t inc) noexcept
Addition assignment operator.
Definition: InitializerIterator.h:199
PointerType pointer
Pointer return type.
Definition: InitializerIterator.h:69
size_t index() const noexcept
Low-level access to the underlying index member of the iterator.
Definition: InitializerIterator.h:358
ReferenceType reference
Reference return type.
Definition: InitializerIterator.h:70
const Type & ReferenceType
Reference return type.
Definition: InitializerIterator.h:63
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: InitializerIterator.h:60
static const Type zero_
Neutral element for accesses to zero elements.
Definition: InitializerIterator.h:133
InitializerIterator() noexcept
Default constructor for the InitializerIterator class.
Definition: InitializerIterator.h:163
initializer_list< Type > list() const noexcept
Low-level access to the underlying list member of the iterator.
Definition: InitializerIterator.h:371
InitializerIterator & operator--() noexcept
Pre-decrement operator.
Definition: InitializerIterator.h:263
InitializerIterator & operator++() noexcept
Pre-increment operator.
Definition: InitializerIterator.h:236
ReferenceType operator*() const noexcept
Direct access to the element at the current iterator position.
Definition: InitializerIterator.h:317
initializer_list< Type > list_
The initializer list to be traversed.
Definition: InitializerIterator.h:131
ValueType value_type
Type of the underlying elements.
Definition: InitializerIterator.h:68
ReferenceType operator[](size_t index) const noexcept
Direct access to the underlying elements.
Definition: InitializerIterator.h:300
InitializerIterator & operator-=(ptrdiff_t dec) noexcept
Subtraction assignment operator.
Definition: InitializerIterator.h:214
Type ValueType
Type of the underlying elements.
Definition: InitializerIterator.h:61
IteratorCategory iterator_category
The iterator category.
Definition: InitializerIterator.h:67
DifferenceType difference_type
Difference between two iterators.
Definition: InitializerIterator.h:71
PointerType operator->() const noexcept
Direct access to the element at the current iterator position.
Definition: InitializerIterator.h:334
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
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
Header file for the extended initializer_list functionality.
Header file for basic type definitions.