Dune Core Modules (2.3.1)

iteratorfacades.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // $Id$
4 #ifndef DUNE_ITERATORFACADES_HH
5 #define DUNE_ITERATORFACADES_HH
6 #include <iterator>
7 #include "typetraits.hh"
8 
9 namespace Dune
10 {
135  template<class T, class V, class R = V&, class D = std::ptrdiff_t>
137  public std::iterator< std::forward_iterator_tag,
138  typename remove_const<V>::type, // std::iterator needs mutable value type
139  D,
140  V*,
141  R>
142  {
143 
144  public:
169  typedef T DerivedType;
170 
174  typedef V Value;
175 
179  typedef V* Pointer;
180 
184  typedef D DifferenceType;
185 
189  typedef R Reference;
190 
193  {
194  return static_cast<DerivedType const*>(this)->dereference();
195  }
196 
197  Pointer operator->() const
198  {
199  return &(static_cast<const DerivedType *>(this)->dereference());
200  }
201 
204  {
205  static_cast<DerivedType *>(this)->increment();
206  return *static_cast<DerivedType *>(this);
207  }
208 
211  {
212  DerivedType tmp(static_cast<DerivedType const&>(*this));
213  this->operator++();
214  return tmp;
215  }
216  };
217 
228  template<class T1, class V1, class R1, class D,
229  class T2, class V2, class R2>
230  inline typename EnableIfInterOperable<T1,T2,bool>::type
233  {
235  return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
236  else
237  return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
238  }
239 
250  template<class T1, class V1, class R1, class D,
251  class T2, class V2, class R2>
252  inline typename EnableIfInterOperable<T1,T2,bool>::type
255  {
257  return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
258  else
259  return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
260  }
261 
266  template<class T, class V, class R = V&, class D = std::ptrdiff_t>
268  public std::iterator< std::bidirectional_iterator_tag,
269  typename remove_const<V>::type, // std::iterator needs mutable value type
270  D,
271  V*,
272  R>
273  {
274 
275  public:
301  typedef T DerivedType;
302 
306  typedef V Value;
307 
311  typedef V* Pointer;
312 
316  typedef D DifferenceType;
317 
321  typedef R Reference;
322 
325  {
326  return static_cast<DerivedType const*>(this)->dereference();
327  }
328 
329  Pointer operator->() const
330  {
331  return &(static_cast<const DerivedType *>(this)->dereference());
332  }
333 
336  {
337  static_cast<DerivedType *>(this)->increment();
338  return *static_cast<DerivedType *>(this);
339  }
340 
343  {
344  DerivedType tmp(static_cast<DerivedType const&>(*this));
345  this->operator++();
346  return tmp;
347  }
348 
349 
352  {
353  static_cast<DerivedType *>(this)->decrement();
354  return *static_cast<DerivedType *>(this);
355  }
356 
359  {
360  DerivedType tmp(static_cast<DerivedType const&>(*this));
361  this->operator--();
362  return tmp;
363  }
364  };
365 
373  template<class T1, class V1, class R1, class D,
374  class T2, class V2, class R2>
375  inline typename enable_if<Conversion<T2,T1>::exists,bool>::type
378  {
379  return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
380  }
381 
390  template<class T1, class V1, class R1, class D,
391  class T2, class V2, class R2>
392  inline
393  typename enable_if<Conversion<T1,T2>::exists && !Conversion<T2,T1>::exists,
394  bool>::type
397  {
398  return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
399  }
400 
411  template<class T1, class V1, class R1, class D,
412  class T2, class V2, class R2>
413  inline typename EnableIfInterOperable<T1,T2,bool>::type
416  {
417  return !(lhs == rhs);
418  }
419 
424  template<class T, class V, class R = V&, class D = std::ptrdiff_t>
426  public std::iterator< std::random_access_iterator_tag,
427  typename remove_const<V>::type, // std::iterator needs mutable value type
428  D,
429  V*,
430  R>
431  {
432 
433  public:
467  typedef T DerivedType;
468 
472  typedef V Value;
473 
477  typedef V* Pointer;
478 
482  typedef D DifferenceType;
483 
487  typedef R Reference;
488 
491  {
492  return static_cast<DerivedType const*>(this)->dereference();
493  }
494 
495  Pointer operator->() const
496  {
497  return &(static_cast<const DerivedType *>(this)->dereference());
498  }
499 
506  {
507  return static_cast<const DerivedType *>(this)->elementAt(n);
508  }
509 
512  {
513  static_cast<DerivedType *>(this)->increment();
514  return *static_cast<DerivedType *>(this);
515  }
516 
519  {
520  DerivedType tmp(static_cast<DerivedType const&>(*this));
521  this->operator++();
522  return tmp;
523  }
524 
525  DerivedType& operator+=(DifferenceType n)
526  {
527  static_cast<DerivedType *>(this)->advance(n);
528  return *static_cast<DerivedType *>(this);
529  }
530 
531  DerivedType operator+(DifferenceType n) const
532  {
533  DerivedType tmp(static_cast<DerivedType const&>(*this));
534  tmp.advance(n);
535  return tmp;
536  }
537 
538 
541  {
542  static_cast<DerivedType *>(this)->decrement();
543  return *static_cast<DerivedType *>(this);
544  }
545 
548  {
549  DerivedType tmp(static_cast<DerivedType const&>(*this));
550  this->operator--();
551  return tmp;
552  }
553 
554  DerivedType& operator-=(DifferenceType n)
555  {
556  static_cast<DerivedType *>(this)->advance(-n);
557  return *static_cast<DerivedType *>(this);
558  }
559 
560  DerivedType operator-(DifferenceType n) const
561  {
562  DerivedType tmp(static_cast<DerivedType const&>(*this));
563  tmp.advance(-n);
564  return tmp;
565  }
566 
567 
568  };
569 
580  template<class T1, class V1, class R1, class D,
581  class T2, class V2, class R2>
582  inline typename EnableIfInterOperable<T1,T2,bool>::type
585  {
587  return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
588  else
589  return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
590  }
591 
602  template<class T1, class V1, class R1, class D,
603  class T2, class V2, class R2>
604  inline typename EnableIfInterOperable<T1,T2,bool>::type
607  {
609  return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
610  else
611  return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
612  }
613 
624  template<class T1, class V1, class R1, class D,
625  class T2, class V2, class R2>
626  inline typename EnableIfInterOperable<T1,T2,bool>::type
627  operator<(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
629  {
631  return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>0;
632  else
633  return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<0;
634  }
635 
636 
647  template<class T1, class V1, class R1, class D,
648  class T2, class V2, class R2>
649  inline typename EnableIfInterOperable<T1,T2,bool>::type
650  operator<=(const RandomAccessIteratorFacade<T1,V1,R1,D>& lhs,
652  {
654  return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>=0;
655  else
656  return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<=0;
657  }
658 
659 
670  template<class T1, class V1, class R1, class D,
671  class T2, class V2, class R2>
672  inline typename EnableIfInterOperable<T1,T2,bool>::type
675  {
677  return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<0;
678  else
679  return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>0;
680  }
681 
692  template<class T1, class V1, class R1, class D,
693  class T2, class V2, class R2>
694  inline typename EnableIfInterOperable<T1,T2,bool>::type
697  {
699  return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<=0;
700  else
701  return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>=0;
702  }
703 
714  template<class T1, class V1, class R1, class D,
715  class T2, class V2, class R2>
716  inline typename EnableIfInterOperable<T1,T2,D>::type
719  {
721  return -static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs));
722  else
723  return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs));
724  }
725 
727 }
728 #endif
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:273
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:335
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:324
DerivedType & operator--()
Preincrement operator.
Definition: iteratorfacades.hh:351
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:301
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:311
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:321
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:342
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:316
DerivedType operator--(int)
Postincrement operator.
Definition: iteratorfacades.hh:358
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:306
Checks wether a type is convertible to another.
Definition: typetraits.hh:213
@ exists
True if the conversion exists.
Definition: typetraits.hh:223
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:142
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:184
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:189
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:169
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:174
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:203
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:210
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:179
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:192
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:431
DerivedType operator--(int)
Postdecrement operator.
Definition: iteratorfacades.hh:547
DerivedType & operator--()
Predecrement operator.
Definition: iteratorfacades.hh:540
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:490
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:482
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:511
Reference operator[](DifferenceType n) const
Get the element n positions from the current one.
Definition: iteratorfacades.hh:505
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:467
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:477
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:518
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:472
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:487
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:253
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:231
Dune namespace.
Definition: alignment.hh:14
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)