Dune Core Modules (2.5.0)

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
6#include <iterator>
7#include <type_traits>
8
9#include "typetraits.hh"
10
11namespace Dune
12{
137 template<class T, class V, class R = V&, class D = std::ptrdiff_t>
139 public std::iterator< std::forward_iterator_tag,
140 typename std::remove_const<V>::type, // std::iterator needs mutable value type
141 D,
142 V*,
143 R>
144 {
145
146 public:
171 typedef T DerivedType;
172
176 typedef V Value;
177
181 typedef V* Pointer;
182
186 typedef D DifferenceType;
187
191 typedef R Reference;
192
195 {
196 return static_cast<DerivedType const*>(this)->dereference();
197 }
198
199 Pointer operator->() const
200 {
201 return &(static_cast<const DerivedType *>(this)->dereference());
202 }
203
206 {
207 static_cast<DerivedType *>(this)->increment();
208 return *static_cast<DerivedType *>(this);
209 }
210
213 {
214 DerivedType tmp(static_cast<DerivedType const&>(*this));
215 this->operator++();
216 return tmp;
217 }
218 };
219
230 template<class T1, class V1, class R1, class D,
231 class T2, class V2, class R2>
232 inline typename EnableIfInterOperable<T1,T2,bool>::type
235 {
236 if(std::is_convertible<T2,T1>::value)
237 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
238 else
239 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
240 }
241
252 template<class T1, class V1, class R1, class D,
253 class T2, class V2, class R2>
254 inline typename EnableIfInterOperable<T1,T2,bool>::type
257 {
258 if(std::is_convertible<T2,T1>::value)
259 return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
260 else
261 return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
262 }
263
268 template<class T, class V, class R = V&, class D = std::ptrdiff_t>
270 public std::iterator< std::bidirectional_iterator_tag,
271 typename std::remove_const<V>::type, // std::iterator needs mutable value type
272 D,
273 V*,
274 R>
275 {
276
277 public:
303 typedef T DerivedType;
304
308 typedef V Value;
309
313 typedef V* Pointer;
314
318 typedef D DifferenceType;
319
323 typedef R Reference;
324
327 {
328 return static_cast<DerivedType const*>(this)->dereference();
329 }
330
331 Pointer operator->() const
332 {
333 return &(static_cast<const DerivedType *>(this)->dereference());
334 }
335
338 {
339 static_cast<DerivedType *>(this)->increment();
340 return *static_cast<DerivedType *>(this);
341 }
342
345 {
346 DerivedType tmp(static_cast<DerivedType const&>(*this));
347 this->operator++();
348 return tmp;
349 }
350
351
354 {
355 static_cast<DerivedType *>(this)->decrement();
356 return *static_cast<DerivedType *>(this);
357 }
358
361 {
362 DerivedType tmp(static_cast<DerivedType const&>(*this));
363 this->operator--();
364 return tmp;
365 }
366 };
367
375 template<class T1, class V1, class R1, class D,
376 class T2, class V2, class R2>
377 inline typename std::enable_if<std::is_convertible<T2,T1>::value,bool>::type
380 {
381 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
382 }
383
392 template<class T1, class V1, class R1, class D,
393 class T2, class V2, class R2>
394 inline
395 typename std::enable_if<std::is_convertible<T1,T2>::value && !std::is_convertible<T2,T1>::value,
396 bool>::type
399 {
400 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
401 }
402
413 template<class T1, class V1, class R1, class D,
414 class T2, class V2, class R2>
415 inline typename EnableIfInterOperable<T1,T2,bool>::type
418 {
419 return !(lhs == rhs);
420 }
421
426 template<class T, class V, class R = V&, class D = std::ptrdiff_t>
428 public std::iterator< std::random_access_iterator_tag,
429 typename std::remove_const<V>::type, // std::iterator needs mutable value type
430 D,
431 V*,
432 R>
433 {
434
435 public:
469 typedef T DerivedType;
470
474 typedef V Value;
475
479 typedef V* Pointer;
480
484 typedef D DifferenceType;
485
489 typedef R Reference;
490
493 {
494 return static_cast<DerivedType const*>(this)->dereference();
495 }
496
497 Pointer operator->() const
498 {
499 return &(static_cast<const DerivedType *>(this)->dereference());
500 }
501
508 {
509 return static_cast<const DerivedType *>(this)->elementAt(n);
510 }
511
514 {
515 static_cast<DerivedType *>(this)->increment();
516 return *static_cast<DerivedType *>(this);
517 }
518
521 {
522 DerivedType tmp(static_cast<DerivedType const&>(*this));
523 this->operator++();
524 return tmp;
525 }
526
527 DerivedType& operator+=(DifferenceType n)
528 {
529 static_cast<DerivedType *>(this)->advance(n);
530 return *static_cast<DerivedType *>(this);
531 }
532
533 DerivedType operator+(DifferenceType n) const
534 {
535 DerivedType tmp(static_cast<DerivedType const&>(*this));
536 tmp.advance(n);
537 return tmp;
538 }
539
540
543 {
544 static_cast<DerivedType *>(this)->decrement();
545 return *static_cast<DerivedType *>(this);
546 }
547
550 {
551 DerivedType tmp(static_cast<DerivedType const&>(*this));
552 this->operator--();
553 return tmp;
554 }
555
556 DerivedType& operator-=(DifferenceType n)
557 {
558 static_cast<DerivedType *>(this)->advance(-n);
559 return *static_cast<DerivedType *>(this);
560 }
561
562 DerivedType operator-(DifferenceType n) const
563 {
564 DerivedType tmp(static_cast<DerivedType const&>(*this));
565 tmp.advance(-n);
566 return tmp;
567 }
568
569
570 };
571
582 template<class T1, class V1, class R1, class D,
583 class T2, class V2, class R2>
584 inline typename EnableIfInterOperable<T1,T2,bool>::type
587 {
588 if(std::is_convertible<T2,T1>::value)
589 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
590 else
591 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
592 }
593
604 template<class T1, class V1, class R1, class D,
605 class T2, class V2, class R2>
606 inline typename EnableIfInterOperable<T1,T2,bool>::type
609 {
610 if(std::is_convertible<T2,T1>::value)
611 return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
612 else
613 return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
614 }
615
626 template<class T1, class V1, class R1, class D,
627 class T2, class V2, class R2>
631 {
632 if(std::is_convertible<T2,T1>::value)
633 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>0;
634 else
635 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<0;
636 }
637
638
649 template<class T1, class V1, class R1, class D,
650 class T2, class V2, class R2>
654 {
655 if(std::is_convertible<T2,T1>::value)
656 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>=0;
657 else
658 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<=0;
659 }
660
661
672 template<class T1, class V1, class R1, class D,
673 class T2, class V2, class R2>
674 inline typename EnableIfInterOperable<T1,T2,bool>::type
677 {
678 if(std::is_convertible<T2,T1>::value)
679 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<0;
680 else
681 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>0;
682 }
683
694 template<class T1, class V1, class R1, class D,
695 class T2, class V2, class R2>
696 inline typename EnableIfInterOperable<T1,T2,bool>::type
699 {
700 if(std::is_convertible<T2,T1>::value)
701 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<=0;
702 else
703 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>=0;
704 }
705
716 template<class T1, class V1, class R1, class D,
717 class T2, class V2, class R2>
718 inline typename EnableIfInterOperable<T1,T2,D>::type
721 {
722 if(std::is_convertible<T2,T1>::value)
723 return -static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs));
724 else
725 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs));
726 }
727
729}
730#endif
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:275
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:326
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:303
DerivedType & operator--()
Preincrement operator.
Definition: iteratorfacades.hh:353
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:337
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:313
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:323
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:344
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:318
DerivedType operator--(int)
Postincrement operator.
Definition: iteratorfacades.hh:360
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:308
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:144
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:205
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:186
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:191
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:171
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:176
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:212
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:181
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:194
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:433
DerivedType operator--(int)
Postdecrement operator.
Definition: iteratorfacades.hh:549
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:492
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:513
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:484
DerivedType & operator--()
Predecrement operator.
Definition: iteratorfacades.hh:542
Reference operator[](DifferenceType n) const
Get the element n positions from the current one.
Definition: iteratorfacades.hh:507
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:469
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:479
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:520
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:474
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:489
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:441
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:138
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:629
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:675
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:652
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:233
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:697
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:255
Dune namespace.
Definition: alignment.hh:11
Enable typedef if two types are interoperable.
Definition: typetraits.hh:176
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)