PtrIterator.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_PTRITERATOR_H_
36 #define _BLAZE_UTIL_PTRITERATOR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <iterator>
44 
45 
46 namespace blaze {
47 
48 //=================================================================================================
49 //
50 // CLASS DEFINITION
51 //
52 //=================================================================================================
53 
54 //*************************************************************************************************
106 template< typename Type >
108 {
109  public:
110  //**Type definitions****************************************************************************
111  // blaze naming convention
112  typedef std::random_access_iterator_tag IteratorCategory;
113  typedef Type* ValueType;
114  typedef Type* PointerType;
115  typedef ValueType const& ReferenceType;
116  typedef ValueType const* IteratorType;
117  typedef std::ptrdiff_t DifferenceType;
118 
119  // STL iterator requirements
120  typedef IteratorCategory iterator_category;
121  typedef ValueType value_type;
122  typedef PointerType pointer;
123  typedef ReferenceType reference;
124  typedef DifferenceType difference_type;
125  //**********************************************************************************************
126 
127  //**Constructors********************************************************************************
130  inline PtrIterator();
131  explicit inline PtrIterator( const IteratorType& it );
132 
133  template< typename Other >
134  inline PtrIterator( const PtrIterator<Other>& it );
135 
136  // No explicitly declared copy constructor.
138  //**********************************************************************************************
139 
140  //**Destructor**********************************************************************************
141  // No explicitly declared destructor.
142  //**********************************************************************************************
143 
144  //**Copy assignment operator********************************************************************
145  // No explicitly declared copy assignment operator.
146  //**********************************************************************************************
147 
148  //**Operators***********************************************************************************
151  inline PtrIterator& operator++();
152  inline PtrIterator operator++( int );
153  inline PtrIterator& operator--();
154  inline PtrIterator operator--( int );
155  inline PtrIterator& operator+=( DifferenceType n );
156  inline PtrIterator operator+ ( DifferenceType n ) const;
157  inline PtrIterator& operator-=( DifferenceType n );
158  inline PtrIterator operator- ( DifferenceType n ) const;
159  inline DifferenceType operator- ( const PtrIterator& it ) const;
161  //**********************************************************************************************
162 
163  //**Access operators****************************************************************************
166  inline PointerType operator[]( DifferenceType n ) const;
167  inline PointerType operator*() const;
168  inline PointerType operator->() const;
170  //**********************************************************************************************
171 
172  //**Utility functions***************************************************************************
175  inline const IteratorType& base() const;
177  //**********************************************************************************************
178 
179  private:
180  //**Member variables****************************************************************************
183  IteratorType it_;
184 
185  //**********************************************************************************************
186 };
187 //*************************************************************************************************
188 
189 
190 
191 
192 //=================================================================================================
193 //
194 // CONSTRUCTORS
195 //
196 //=================================================================================================
197 
198 //*************************************************************************************************
201 template< typename Type >
203  : it_( nullptr ) // Pointer to the current memory location
204 {}
205 //*************************************************************************************************
206 
207 
208 //*************************************************************************************************
213 template< typename Type >
215  : it_( it ) // Pointer to the current memory location
216 {}
217 //*************************************************************************************************
218 
219 
220 //*************************************************************************************************
225 template< typename Type >
226 template< typename Other >
228  : it_( it.base() ) // Pointer to the current memory location
229 {}
230 //*************************************************************************************************
231 
232 
233 
234 
235 //=================================================================================================
236 //
237 // OPERATORS
238 //
239 //=================================================================================================
240 
241 //*************************************************************************************************
246 template< typename Type >
248 {
249  ++it_;
250  return *this;
251 }
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
260 template< typename Type >
262 {
263  PtrIterator tmp( *this );
264  ++it_;
265  return tmp;
266 }
267 //*************************************************************************************************
268 
269 
270 //*************************************************************************************************
275 template< typename Type >
277 {
278  --it_;
279  return *this;
280 }
281 //*************************************************************************************************
282 
283 
284 //*************************************************************************************************
289 template< typename Type >
291 {
292  PtrIterator tmp( *this );
293  --it_;
294  return tmp;
295 }
296 //*************************************************************************************************
297 
298 
299 //*************************************************************************************************
305 template< typename Type >
307 {
308  it_ += n;
309  return *this;
310 }
311 //*************************************************************************************************
312 
313 
314 //*************************************************************************************************
320 template< typename Type >
322 {
323  return PtrIterator( it_ + n );
324 }
325 //*************************************************************************************************
326 
327 
328 //*************************************************************************************************
334 template< typename Type >
336 {
337  it_ -= n;
338  return *this;
339 }
340 //*************************************************************************************************
341 
342 
343 //*************************************************************************************************
349 template< typename Type >
351 {
352  return PtrIterator( it_ - n );
353 }
354 //*************************************************************************************************
355 
356 
357 //*************************************************************************************************
363 template< typename Type >
365 {
366  return it_ - it.it_;
367 }
368 //*************************************************************************************************
369 
370 
371 
372 
373 //=================================================================================================
374 //
375 // ACCESS OPERATORS
376 //
377 //=================================================================================================
378 
379 //*************************************************************************************************
385 template< typename Type >
387 {
388  return it_[index];
389 }
390 //*************************************************************************************************
391 
392 
393 //*************************************************************************************************
398 template< typename Type >
400 {
401  return *it_;
402 }
403 //*************************************************************************************************
404 
405 
406 //*************************************************************************************************
411 template< typename Type >
413 {
414  return *it_;
415 }
416 //*************************************************************************************************
417 
418 
419 
420 
421 //=================================================================================================
422 //
423 // UTILITY FUNCTIONS
424 //
425 //=================================================================================================
426 
427 //*************************************************************************************************
432 template< typename Type >
434 {
435  return it_;
436 }
437 //*************************************************************************************************
438 
439 
440 
441 
442 //=================================================================================================
443 //
444 // GLOBAL OPERATORS
445 //
446 //=================================================================================================
447 
448 //*************************************************************************************************
451 template< typename TypeL, typename TypeR >
452 inline bool operator==( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
453 
454 template< typename TypeL, typename TypeR >
455 inline bool operator!=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
456 
457 template< typename TypeL, typename TypeR >
458 inline bool operator<( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
459 
460 template< typename TypeL, typename TypeR >
461 inline bool operator>( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
462 
463 template< typename TypeL, typename TypeR >
464 inline bool operator<=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
465 
466 template< typename TypeL, typename TypeR >
467 inline bool operator>=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs );
469 //*************************************************************************************************
470 
471 
472 //*************************************************************************************************
479 template< typename TypeL, typename TypeR >
480 inline bool operator==( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
481 {
482  return lhs.base() == rhs.base();
483 }
484 //*************************************************************************************************
485 
486 
487 //*************************************************************************************************
494 template< typename TypeL, typename TypeR >
495 inline bool operator!=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
496 {
497  return lhs.base() != rhs.base();
498 }
499 //*************************************************************************************************
500 
501 
502 //*************************************************************************************************
509 template< typename TypeL, typename TypeR >
510 inline bool operator<( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
511 {
512  return lhs.base() < rhs.base();
513 }
514 //*************************************************************************************************
515 
516 
517 //*************************************************************************************************
524 template< typename TypeL, typename TypeR >
525 inline bool operator>( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
526 {
527  return lhs.base() > rhs.base();
528 }
529 //*************************************************************************************************
530 
531 
532 //*************************************************************************************************
539 template< typename TypeL, typename TypeR >
540 inline bool operator<=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
541 {
542  return lhs.base() <= rhs.base();
543 }
544 //*************************************************************************************************
545 
546 
547 //*************************************************************************************************
554 template< typename TypeL, typename TypeR >
555 inline bool operator>=( const PtrIterator<TypeL>& lhs, const PtrIterator<TypeR>& rhs )
556 {
557  return lhs.base() >= rhs.base();
558 }
559 //*************************************************************************************************
560 
561 } // namespace blaze
562 
563 #endif
PointerType pointer
Pointer return type.
Definition: PtrIterator.h:122
Type * ValueType
Type of the underlying pointers.
Definition: PtrIterator.h:113
PtrIterator & operator++()
Pre-increment operator.
Definition: PtrIterator.h:247
PtrIterator & operator-=(DifferenceType n)
Shifting the iterator by n elements to the lower elements.
Definition: PtrIterator.h:335
PtrIterator & operator--()
Pre-decrement operator.
Definition: PtrIterator.h:276
ValueType const & ReferenceType
Reference return type.
Definition: PtrIterator.h:115
bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:366
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:442
std::random_access_iterator_tag IteratorCategory
The iterator category.
Definition: PtrIterator.h:112
Type * PointerType
Pointer return type.
Definition: PtrIterator.h:114
IteratorType it_
Pointer to the current memory location.
Definition: PtrIterator.h:183
PtrIterator & operator+=(DifferenceType n)
Shifting the iterator by n elements to the higher elements.
Definition: PtrIterator.h:306
PointerType operator[](DifferenceType n) const
Subscript operator for the direct element access.
Definition: PtrIterator.h:386
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
PtrIterator operator+(DifferenceType n) const
Shifting the iterator by n elements to the higher elements.
Definition: PtrIterator.h:321
Implementation of an iterator for pointer vectors.The PtrIterator class follows the example of the ra...
Definition: PtrIterator.h:107
std::ptrdiff_t DifferenceType
Difference between two iterators.
Definition: PtrIterator.h:117
PtrIterator operator-(DifferenceType n) const
Shifting the iterator by n elements to the lower elements.
Definition: PtrIterator.h:350
ReferenceType reference
Reference return type.
Definition: PtrIterator.h:123
ValueType const * IteratorType
Type of the internal pointer.
Definition: PtrIterator.h:116
PointerType operator*() const
Returns a handle to the element at the current iterator position.
Definition: PtrIterator.h:399
PointerType operator->() const
Direct access to the element at the current iterator position.
Definition: PtrIterator.h:412
ValueType value_type
Type of the underlying pointers.
Definition: PtrIterator.h:121
DifferenceType difference_type
Difference between two iterators.
Definition: PtrIterator.h:124
IteratorCategory iterator_category
The iterator category.
Definition: PtrIterator.h:120
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
const IteratorType & base() const
Access to the underlying member of the pointer iterator.
Definition: PtrIterator.h:433
PtrIterator()
Default constructor for PtrIterator.
Definition: PtrIterator.h:202