Blaze  3.6
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 
39 namespace blaze {
40 
41 //=================================================================================================
42 //
43 // CLASS DEFINITION
44 //
45 //=================================================================================================
46 
47 //*************************************************************************************************
55 template< 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&;
65 
66  // STL iterator requirements
69  using pointer = PointerType;
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_;
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 
147 template< typename Type > // Type of the elements
148 const Type InitializerIterator<Type>::zero_{};
149 
150 
151 
152 
153 //=================================================================================================
154 //
155 // CONSTRUCTORS
156 //
157 //=================================================================================================
158 
159 //*************************************************************************************************
162 template< 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 //*************************************************************************************************
176 template< typename Type > // Type of the elements
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 //*************************************************************************************************
198 template< typename Type > // Type of the elements
200 {
201  index_ += inc;
202  return *this;
203 }
204 //*************************************************************************************************
205 
206 
207 //*************************************************************************************************
213 template< 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 //*************************************************************************************************
235 template< typename Type > // Type of the elements
237 {
238  ++index_;
239  return *this;
240 }
241 //*************************************************************************************************
242 
243 
244 //*************************************************************************************************
249 template< typename Type > // Type of the elements
251 {
252  return InitializerIterator( index_++, list_ );
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
262 template< typename Type > // Type of the elements
264 {
265  --index_;
266  return *this;
267 }
268 //*************************************************************************************************
269 
270 
271 //*************************************************************************************************
276 template< 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 //*************************************************************************************************
298 template< 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 //*************************************************************************************************
315 template< 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 //*************************************************************************************************
332 template< 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 //*************************************************************************************************
357 template< typename Type > // Type of the elements
358 inline size_t InitializerIterator<Type>::index() const noexcept
359 {
360  return index_;
361 }
362 //*************************************************************************************************
363 
364 
365 //*************************************************************************************************
370 template< typename Type > // Type of the elements
372 {
373  return list_;
374 }
375 //*************************************************************************************************
376 
377 
378 
379 
380 //=================================================================================================
381 //
382 // GLOBAL OPERATORS
383 //
384 //=================================================================================================
385 
386 //*************************************************************************************************
389 template< typename Type >
390 bool operator==( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
391 
392 template< typename Type >
393 bool operator!=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
394 
395 template< typename Type >
396 bool operator<( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
397 
398 template< typename Type >
399 bool operator>( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
400 
401 template< typename Type >
402 bool operator<=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
403 
404 template< typename Type >
405 bool operator>=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
406 
407 template< typename Type >
409 
410 template< typename Type >
412 
413 template< typename Type >
415 
416 template< typename Type >
419 //*************************************************************************************************
420 
421 
422 //*************************************************************************************************
429 template< typename Type > // Type of the elements
430 inline bool operator==( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
431 {
432  return lhs.index() == rhs.index();
433 }
434 //*************************************************************************************************
435 
436 
437 //*************************************************************************************************
444 template< typename Type > // Type of the elements
445 inline bool operator!=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
446 {
447  return lhs.index() != rhs.index();
448 }
449 //*************************************************************************************************
450 
451 
452 //*************************************************************************************************
459 template< typename Type > // Type of the elements
460 inline bool operator<( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
461 {
462  return lhs.index() < rhs.index();
463 }
464 //*************************************************************************************************
465 
466 
467 //*************************************************************************************************
474 template< typename Type > // Type of the elements
475 inline bool operator>( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
476 {
477  return lhs.index() > rhs.index();
478 }
479 //*************************************************************************************************
480 
481 
482 //*************************************************************************************************
489 template< typename Type > // Type of the elements
490 inline bool operator<=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
491 {
492  return lhs.index() <= rhs.index();
493 }
494 //*************************************************************************************************
495 
496 
497 //*************************************************************************************************
504 template< typename Type > // Type of the elements
505 inline bool operator>=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
506 {
507  return lhs.index() >= rhs.index();
508 }
509 //*************************************************************************************************
510 
511 
512 //*************************************************************************************************
519 template< typename Type > // Type of the elements
521 {
522  return InitializerIterator<Type>( it.index() + inc, it.list() );
523 }
524 //*************************************************************************************************
525 
526 
527 //*************************************************************************************************
534 template< typename Type > // Type of the elements
536 {
537  return InitializerIterator<Type>( it.index() + inc, it.list() );
538 }
539 //*************************************************************************************************
540 
541 
542 //*************************************************************************************************
549 template< typename Type > // Type of the elements
551 {
552  return InitializerIterator<Type>( it.index() - dec, it.list() );
553 }
554 //*************************************************************************************************
555 
556 
557 //*************************************************************************************************
564 template< typename Type > // Type of the elements
566 {
567  return lhs.index() - rhs.index();
568 }
569 //*************************************************************************************************
570 
571 } // namespace blaze
572 
573 #endif
Pointer difference type of the Blaze library.
IteratorCategory iterator_category
The iterator category.
Definition: InitializerIterator.h:67
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
Implementation of an iterator for (extended) initializer lists.The InitializerIterator represents a g...
Definition: InitializerIterator.h:56
size_t index() const noexcept
Low-level access to the underlying index member of the iterator.
Definition: InitializerIterator.h:358
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
initializer_list< Type > list() const noexcept
Low-level access to the underlying list member of the iterator.
Definition: InitializerIterator.h:371
PointerType pointer
Pointer return type.
Definition: InitializerIterator.h:69
ReferenceType reference
Reference return type.
Definition: InitializerIterator.h:70
initializer_list< Type > list_
The initializer list to be traversed.
Definition: InitializerIterator.h:131
Header file for the extended initializer_list functionality.
const Type * PointerType
Pointer return type.
Definition: InitializerIterator.h:62
Type ValueType
Type of the underlying elements.
Definition: InitializerIterator.h:61
const Type & ReferenceType
Reference return type.
Definition: InitializerIterator.h:63
ValueType value_type
Type of the underlying elements.
Definition: InitializerIterator.h:68
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: InitializerIterator.h:60
size_t index_
Current index of the iterator within the initializer list.
Definition: InitializerIterator.h:130
ReferenceType operator *() const noexcept
Direct access to the element at the current iterator position.
Definition: InitializerIterator.h:317
InitializerIterator & operator-=(ptrdiff_t dec) noexcept
Subtraction assignment operator.
Definition: InitializerIterator.h:214
ReferenceType operator[](size_t index) const noexcept
Direct access to the underlying elements.
Definition: InitializerIterator.h:300
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
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
ptrdiff_t DifferenceType
Difference between two iterators.
Definition: InitializerIterator.h:64
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
static const Type zero_
Neutral element for accesses to zero elements.
Definition: InitializerIterator.h:133
InitializerIterator & operator++() noexcept
Pre-increment operator.
Definition: InitializerIterator.h:236
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
InitializerIterator & operator+=(ptrdiff_t inc) noexcept
Addition assignment operator.
Definition: InitializerIterator.h:199
PointerType operator->() const noexcept
Direct access to the element at the current iterator position.
Definition: InitializerIterator.h:334
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
InitializerIterator & operator--() noexcept
Pre-decrement operator.
Definition: InitializerIterator.h:263
Initializer list type of the Blaze library.
InitializerIterator() noexcept
Default constructor for the InitializerIterator class.
Definition: InitializerIterator.h:163