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  // No explicitly declared copy constructor.
81  //**********************************************************************************************
82 
83  //**Destructor**********************************************************************************
84  // No explicitly declared destructor.
85  //**********************************************************************************************
86 
87  //**Assignment operators************************************************************************
90  // No explicitly declared copy assignment operator.
91  inline InitializerIterator& operator+=( ptrdiff_t inc ) noexcept;
92  inline InitializerIterator& operator-=( ptrdiff_t dec ) noexcept;
94  //**********************************************************************************************
95 
96  //**Increment/decrement operators***************************************************************
99  inline InitializerIterator& operator++() noexcept;
100  inline const InitializerIterator operator++( int ) noexcept;
101  inline InitializerIterator& operator--() noexcept;
102  inline const InitializerIterator operator--( int ) noexcept;
104  //**********************************************************************************************
105 
106  //**Access operators****************************************************************************
109  inline ReferenceType operator[]( size_t index ) const noexcept;
110  inline ReferenceType operator* () const noexcept;
111  inline PointerType operator->() const noexcept;
113  //**********************************************************************************************
114 
115  //**Utility functions***************************************************************************
118  inline size_t index() const noexcept;
119  inline initializer_list<Type> list () const noexcept;
121  //**********************************************************************************************
122 
123  private:
124  //**Member variables****************************************************************************
125  size_t index_;
127 
128  static const Type zero_;
129  //**********************************************************************************************
130 };
131 //*************************************************************************************************
132 
133 
134 
135 
136 //=================================================================================================
137 //
138 // DEFINITION AND INITIALIZATION OF THE STATIC MEMBER VARIABLES
139 //
140 //=================================================================================================
141 
142 template< typename Type > // Type of the elements
143 const Type InitializerIterator<Type>::zero_{};
144 
145 
146 
147 
148 //=================================================================================================
149 //
150 // CONSTRUCTORS
151 //
152 //=================================================================================================
153 
154 //*************************************************************************************************
157 template< typename Type > // Type of the elements
159  : index_() // Current index of the iterator within the initializer list
160  , list_ () // The initializer list to be traversed
161 {}
162 //*************************************************************************************************
163 
164 
165 //*************************************************************************************************
171 template< typename Type > // Type of the elements
173  : index_( index ) // Current index of the iterator within the initializer list
174  , list_ ( list ) // The initializer list to be traversed
175 {}
176 //*************************************************************************************************
177 
178 
179 
180 
181 //=================================================================================================
182 //
183 // ASSIGNMENT OPERATORS
184 //
185 //=================================================================================================
186 
187 //*************************************************************************************************
193 template< typename Type > // Type of the elements
195 {
196  index_ += inc;
197  return *this;
198 }
199 //*************************************************************************************************
200 
201 
202 //*************************************************************************************************
208 template< typename Type > // Type of the elements
210 {
211  index_ -= dec;
212  return *this;
213 }
214 //*************************************************************************************************
215 
216 
217 
218 
219 //=================================================================================================
220 //
221 // INCREMENT/DECREMENT OPERATORS
222 //
223 //=================================================================================================
224 
225 //*************************************************************************************************
230 template< typename Type > // Type of the elements
232 {
233  ++index_;
234  return *this;
235 }
236 //*************************************************************************************************
237 
238 
239 //*************************************************************************************************
244 template< typename Type > // Type of the elements
246 {
247  return InitializerIterator( index_++, list_ );
248 }
249 //*************************************************************************************************
250 
251 
252 //*************************************************************************************************
257 template< typename Type > // Type of the elements
259 {
260  --index_;
261  return *this;
262 }
263 //*************************************************************************************************
264 
265 
266 //*************************************************************************************************
271 template< typename Type > // Type of the elements
273 {
274  return InitializerIterator( index_--, list_ );
275 }
276 //*************************************************************************************************
277 
278 
279 
280 
281 //=================================================================================================
282 //
283 // ACCESS OPERATORS
284 //
285 //=================================================================================================
286 
287 //*************************************************************************************************
293 template< typename Type > // Type of the elements
296 {
297  if( index < list_.size() )
298  return list_.begin()[index];
299  else
300  return zero_;
301 }
302 //*************************************************************************************************
303 
304 
305 //*************************************************************************************************
310 template< typename Type > // Type of the elements
313 {
314  if( index_ < list_.size() )
315  return list_.begin()[index_];
316  else
317  return zero_;
318 }
319 //*************************************************************************************************
320 
321 
322 //*************************************************************************************************
327 template< typename Type > // Type of the elements
330 {
331  if( index_ < list_.size() )
332  return list_.begin() + index_;
333  else
334  return &zero_;
335 }
336 //*************************************************************************************************
337 
338 
339 
340 
341 //=================================================================================================
342 //
343 // UTILITY FUNCTIONS
344 //
345 //=================================================================================================
346 
347 //*************************************************************************************************
352 template< typename Type > // Type of the elements
353 inline size_t InitializerIterator<Type>::index() const noexcept
354 {
355  return index_;
356 }
357 //*************************************************************************************************
358 
359 
360 //*************************************************************************************************
365 template< typename Type > // Type of the elements
367 {
368  return list_;
369 }
370 //*************************************************************************************************
371 
372 
373 
374 
375 //=================================================================================================
376 //
377 // GLOBAL OPERATORS
378 //
379 //=================================================================================================
380 
381 //*************************************************************************************************
384 template< typename Type >
385 inline bool operator==( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
386 
387 template< typename Type >
388 inline bool operator!=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
389 
390 template< typename Type >
391 inline bool operator<( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
392 
393 template< typename Type >
394 inline bool operator>( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
395 
396 template< typename Type >
397 inline bool operator<=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
398 
399 template< typename Type >
400 inline bool operator>=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
401 
402 template< typename Type >
403 inline const InitializerIterator<Type> operator+( const InitializerIterator<Type>& it, ptrdiff_t inc ) noexcept;
404 
405 template< typename Type >
406 inline const InitializerIterator<Type> operator+( ptrdiff_t inc, const InitializerIterator<Type>& it ) noexcept;
407 
408 template< typename Type >
409 inline const InitializerIterator<Type> operator-( const InitializerIterator<Type>& it, ptrdiff_t dec ) noexcept;
410 
411 template< typename Type >
412 inline ptrdiff_t operator-( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept;
414 //*************************************************************************************************
415 
416 
417 //*************************************************************************************************
424 template< typename Type > // Type of the elements
425 inline bool operator==( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
426 {
427  return lhs.index() == rhs.index();
428 }
429 //*************************************************************************************************
430 
431 
432 //*************************************************************************************************
439 template< typename Type > // Type of the elements
440 inline bool operator!=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
441 {
442  return lhs.index() != rhs.index();
443 }
444 //*************************************************************************************************
445 
446 
447 //*************************************************************************************************
454 template< typename Type > // Type of the elements
455 inline bool operator<( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
456 {
457  return lhs.index() < rhs.index();
458 }
459 //*************************************************************************************************
460 
461 
462 //*************************************************************************************************
469 template< typename Type > // Type of the elements
470 inline bool operator>( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
471 {
472  return lhs.index() > rhs.index();
473 }
474 //*************************************************************************************************
475 
476 
477 //*************************************************************************************************
484 template< typename Type > // Type of the elements
485 inline bool operator<=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
486 {
487  return lhs.index() <= rhs.index();
488 }
489 //*************************************************************************************************
490 
491 
492 //*************************************************************************************************
499 template< typename Type > // Type of the elements
500 inline bool operator>=( const InitializerIterator<Type>& lhs, const InitializerIterator<Type>& rhs ) noexcept
501 {
502  return lhs.index() >= rhs.index();
503 }
504 //*************************************************************************************************
505 
506 
507 //*************************************************************************************************
514 template< typename Type > // Type of the elements
516 {
517  return InitializerIterator<Type>( it.index() + inc, it.list() );
518 }
519 //*************************************************************************************************
520 
521 
522 //*************************************************************************************************
529 template< typename Type > // Type of the elements
531 {
532  return InitializerIterator<Type>( it.index() + inc, it.list() );
533 }
534 //*************************************************************************************************
535 
536 
537 //*************************************************************************************************
544 template< typename Type > // Type of the elements
546 {
547  return InitializerIterator<Type>( it.index() - dec, it.list() );
548 }
549 //*************************************************************************************************
550 
551 
552 //*************************************************************************************************
559 template< typename Type > // Type of the elements
561 {
562  return lhs.index() - rhs.index();
563 }
564 //*************************************************************************************************
565 
566 } // namespace blaze
567 
568 #endif
Pointer difference type of the Blaze library.
IteratorCategory iterator_category
The iterator category.
Definition: InitializerIterator.h:67
Header file for basic type definitions.
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:353
initializer_list< Type > list() const noexcept
Low-level access to the underlying list member of the iterator.
Definition: InitializerIterator.h:366
PointerType pointer
Pointer return type.
Definition: InitializerIterator.h:69
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:701
ReferenceType reference
Reference return type.
Definition: InitializerIterator.h:70
initializer_list< Type > list_
The initializer list to be traversed.
Definition: InitializerIterator.h:126
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:733
ReferenceType operator*() const noexcept
Direct access to the element at the current iterator position.
Definition: InitializerIterator.h:312
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:125
InitializerIterator & operator-=(ptrdiff_t dec) noexcept
Subtraction assignment operator.
Definition: InitializerIterator.h:209
ReferenceType operator[](size_t index) const noexcept
Direct access to the underlying elements.
Definition: InitializerIterator.h:295
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:367
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:443
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
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:290
static const Type zero_
Neutral element for accesses to zero elements.
Definition: InitializerIterator.h:128
InitializerIterator & operator++() noexcept
Pre-increment operator.
Definition: InitializerIterator.h:231
InitializerIterator & operator+=(ptrdiff_t inc) noexcept
Addition assignment operator.
Definition: InitializerIterator.h:194
PointerType operator->() const noexcept
Direct access to the element at the current iterator position.
Definition: InitializerIterator.h:329
InitializerIterator & operator--() noexcept
Pre-decrement operator.
Definition: InitializerIterator.h:258
Initializer list type of the Blaze library.
InitializerIterator() noexcept
Default constructor for the InitializerIterator class.
Definition: InitializerIterator.h:158