Dune Core Modules (2.4.2)

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#ifndef DUNE_ITERATORFACADES_HH
4#define DUNE_ITERATORFACADES_HH
5#include <iterator>
6#include "typetraits.hh"
7
8namespace Dune
9{
134 template<class T, class V, class R = V&, class D = std::ptrdiff_t>
136 public std::iterator< std::forward_iterator_tag,
137 typename remove_const<V>::type, // std::iterator needs mutable value type
138 D,
139 V*,
140 R>
141 {
142
143 public:
168 typedef T DerivedType;
169
173 typedef V Value;
174
178 typedef V* Pointer;
179
183 typedef D DifferenceType;
184
188 typedef R Reference;
189
192 {
193 return static_cast<DerivedType const*>(this)->dereference();
194 }
195
196 Pointer operator->() const
197 {
198 return &(static_cast<const DerivedType *>(this)->dereference());
199 }
200
203 {
204 static_cast<DerivedType *>(this)->increment();
205 return *static_cast<DerivedType *>(this);
206 }
207
210 {
211 DerivedType tmp(static_cast<DerivedType const&>(*this));
212 this->operator++();
213 return tmp;
214 }
215 };
216
227 template<class T1, class V1, class R1, class D,
228 class T2, class V2, class R2>
229 inline typename EnableIfInterOperable<T1,T2,bool>::type
232 {
234 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
235 else
236 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
237 }
238
249 template<class T1, class V1, class R1, class D,
250 class T2, class V2, class R2>
251 inline typename EnableIfInterOperable<T1,T2,bool>::type
254 {
256 return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
257 else
258 return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
259 }
260
265 template<class T, class V, class R = V&, class D = std::ptrdiff_t>
267 public std::iterator< std::bidirectional_iterator_tag,
268 typename remove_const<V>::type, // std::iterator needs mutable value type
269 D,
270 V*,
271 R>
272 {
273
274 public:
300 typedef T DerivedType;
301
305 typedef V Value;
306
310 typedef V* Pointer;
311
315 typedef D DifferenceType;
316
320 typedef R Reference;
321
324 {
325 return static_cast<DerivedType const*>(this)->dereference();
326 }
327
328 Pointer operator->() const
329 {
330 return &(static_cast<const DerivedType *>(this)->dereference());
331 }
332
335 {
336 static_cast<DerivedType *>(this)->increment();
337 return *static_cast<DerivedType *>(this);
338 }
339
342 {
343 DerivedType tmp(static_cast<DerivedType const&>(*this));
344 this->operator++();
345 return tmp;
346 }
347
348
351 {
352 static_cast<DerivedType *>(this)->decrement();
353 return *static_cast<DerivedType *>(this);
354 }
355
358 {
359 DerivedType tmp(static_cast<DerivedType const&>(*this));
360 this->operator--();
361 return tmp;
362 }
363 };
364
372 template<class T1, class V1, class R1, class D,
373 class T2, class V2, class R2>
374 inline typename enable_if<Conversion<T2,T1>::exists,bool>::type
377 {
378 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
379 }
380
389 template<class T1, class V1, class R1, class D,
390 class T2, class V2, class R2>
391 inline
392 typename enable_if<Conversion<T1,T2>::exists && !Conversion<T2,T1>::exists,
393 bool>::type
396 {
397 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
398 }
399
410 template<class T1, class V1, class R1, class D,
411 class T2, class V2, class R2>
412 inline typename EnableIfInterOperable<T1,T2,bool>::type
415 {
416 return !(lhs == rhs);
417 }
418
423 template<class T, class V, class R = V&, class D = std::ptrdiff_t>
425 public std::iterator< std::random_access_iterator_tag,
426 typename remove_const<V>::type, // std::iterator needs mutable value type
427 D,
428 V*,
429 R>
430 {
431
432 public:
466 typedef T DerivedType;
467
471 typedef V Value;
472
476 typedef V* Pointer;
477
481 typedef D DifferenceType;
482
486 typedef R Reference;
487
490 {
491 return static_cast<DerivedType const*>(this)->dereference();
492 }
493
494 Pointer operator->() const
495 {
496 return &(static_cast<const DerivedType *>(this)->dereference());
497 }
498
505 {
506 return static_cast<const DerivedType *>(this)->elementAt(n);
507 }
508
511 {
512 static_cast<DerivedType *>(this)->increment();
513 return *static_cast<DerivedType *>(this);
514 }
515
518 {
519 DerivedType tmp(static_cast<DerivedType const&>(*this));
520 this->operator++();
521 return tmp;
522 }
523
524 DerivedType& operator+=(DifferenceType n)
525 {
526 static_cast<DerivedType *>(this)->advance(n);
527 return *static_cast<DerivedType *>(this);
528 }
529
530 DerivedType operator+(DifferenceType n) const
531 {
532 DerivedType tmp(static_cast<DerivedType const&>(*this));
533 tmp.advance(n);
534 return tmp;
535 }
536
537
540 {
541 static_cast<DerivedType *>(this)->decrement();
542 return *static_cast<DerivedType *>(this);
543 }
544
547 {
548 DerivedType tmp(static_cast<DerivedType const&>(*this));
549 this->operator--();
550 return tmp;
551 }
552
553 DerivedType& operator-=(DifferenceType n)
554 {
555 static_cast<DerivedType *>(this)->advance(-n);
556 return *static_cast<DerivedType *>(this);
557 }
558
559 DerivedType operator-(DifferenceType n) const
560 {
561 DerivedType tmp(static_cast<DerivedType const&>(*this));
562 tmp.advance(-n);
563 return tmp;
564 }
565
566
567 };
568
579 template<class T1, class V1, class R1, class D,
580 class T2, class V2, class R2>
581 inline typename EnableIfInterOperable<T1,T2,bool>::type
584 {
586 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
587 else
588 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
589 }
590
601 template<class T1, class V1, class R1, class D,
602 class T2, class V2, class R2>
603 inline typename EnableIfInterOperable<T1,T2,bool>::type
606 {
608 return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
609 else
610 return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
611 }
612
623 template<class T1, class V1, class R1, class D,
624 class T2, class V2, class R2>
628 {
630 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>0;
631 else
632 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<0;
633 }
634
635
646 template<class T1, class V1, class R1, class D,
647 class T2, class V2, class R2>
651 {
653 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>=0;
654 else
655 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<=0;
656 }
657
658
669 template<class T1, class V1, class R1, class D,
670 class T2, class V2, class R2>
671 inline typename EnableIfInterOperable<T1,T2,bool>::type
674 {
676 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<0;
677 else
678 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>0;
679 }
680
691 template<class T1, class V1, class R1, class D,
692 class T2, class V2, class R2>
693 inline typename EnableIfInterOperable<T1,T2,bool>::type
696 {
698 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<=0;
699 else
700 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>=0;
701 }
702
713 template<class T1, class V1, class R1, class D,
714 class T2, class V2, class R2>
715 inline typename EnableIfInterOperable<T1,T2,D>::type
718 {
720 return -static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs));
721 else
722 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs));
723 }
724
726}
727#endif
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:272
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:323
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:300
DerivedType & operator--()
Preincrement operator.
Definition: iteratorfacades.hh:350
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:334
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:310
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:320
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:341
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:315
DerivedType operator--(int)
Postincrement operator.
Definition: iteratorfacades.hh:357
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:305
Checks wether a type is convertible to another.
Definition: typetraits.hh:177
@ exists
True if the conversion exists.
Definition: typetraits.hh:187
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:141
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:202
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:183
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:188
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:168
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:173
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:209
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:178
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:191
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:430
DerivedType operator--(int)
Postdecrement operator.
Definition: iteratorfacades.hh:546
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:489
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:510
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:481
DerivedType & operator--()
Predecrement operator.
Definition: iteratorfacades.hh:539
Reference operator[](DifferenceType n) const
Get the element n positions from the current one.
Definition: iteratorfacades.hh:504
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:466
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:476
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:517
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:471
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:486
EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:626
EnableIfInterOperable< T1, T2, bool >::type operator>(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:672
EnableIfInterOperable< T1, T2, bool >::type operator<=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:649
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:230
EnableIfInterOperable< T1, T2, bool >::type operator>=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:694
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:252
Dune namespace.
Definition: alignment.hh:10
Enable typedef if two types are interoperable.
Definition: typetraits.hh:292
Traits for type conversions and type information.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)