Dune Core Modules (2.7.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 {
140
141 public:
142 /* type aliases required by C++ for iterators */
143 using iterator_category = std::forward_iterator_tag;
144 using value_type = typename std::remove_const<V>::type;
145 using difference_type = D;
146 using pointer = V*;
147 using reference = R;
148
173 typedef T DerivedType;
174
178 typedef V Value;
179
183 typedef V* Pointer;
184
188 typedef D DifferenceType;
189
193 typedef R Reference;
194
197 {
198 return static_cast<DerivedType const*>(this)->dereference();
199 }
200
201 Pointer operator->() const
202 {
203 return &(static_cast<const DerivedType *>(this)->dereference());
204 }
205
208 {
209 static_cast<DerivedType *>(this)->increment();
210 return *static_cast<DerivedType *>(this);
211 }
212
215 {
216 DerivedType tmp(static_cast<DerivedType const&>(*this));
217 this->operator++();
218 return tmp;
219 }
220 };
221
232 template<class T1, class V1, class R1, class D,
233 class T2, class V2, class R2>
234 inline typename EnableIfInterOperable<T1,T2,bool>::type
237 {
238 if(std::is_convertible<T2,T1>::value)
239 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
240 else
241 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
242 }
243
254 template<class T1, class V1, class R1, class D,
255 class T2, class V2, class R2>
256 inline typename EnableIfInterOperable<T1,T2,bool>::type
259 {
260 if(std::is_convertible<T2,T1>::value)
261 return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
262 else
263 return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
264 }
265
270 template<class T, class V, class R = V&, class D = std::ptrdiff_t>
272 {
273
274 public:
275 /* type aliases required by C++ for iterators */
276 using iterator_category = std::bidirectional_iterator_tag;
277 using value_type = typename std::remove_const<V>::type;
278 using difference_type = D;
279 using pointer = V*;
280 using reference = R;
281
307 typedef T DerivedType;
308
312 typedef V Value;
313
317 typedef V* Pointer;
318
322 typedef D DifferenceType;
323
327 typedef R Reference;
328
331 {
332 return static_cast<DerivedType const*>(this)->dereference();
333 }
334
335 Pointer operator->() const
336 {
337 return &(static_cast<const DerivedType *>(this)->dereference());
338 }
339
342 {
343 static_cast<DerivedType *>(this)->increment();
344 return *static_cast<DerivedType *>(this);
345 }
346
349 {
350 DerivedType tmp(static_cast<DerivedType const&>(*this));
351 this->operator++();
352 return tmp;
353 }
354
355
358 {
359 static_cast<DerivedType *>(this)->decrement();
360 return *static_cast<DerivedType *>(this);
361 }
362
365 {
366 DerivedType tmp(static_cast<DerivedType const&>(*this));
367 this->operator--();
368 return tmp;
369 }
370 };
371
379 template<class T1, class V1, class R1, class D,
380 class T2, class V2, class R2>
381 inline typename std::enable_if<std::is_convertible<T2,T1>::value,bool>::type
384 {
385 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
386 }
387
396 template<class T1, class V1, class R1, class D,
397 class T2, class V2, class R2>
398 inline
399 typename std::enable_if<std::is_convertible<T1,T2>::value && !std::is_convertible<T2,T1>::value,
400 bool>::type
403 {
404 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
405 }
406
417 template<class T1, class V1, class R1, class D,
418 class T2, class V2, class R2>
419 inline typename EnableIfInterOperable<T1,T2,bool>::type
422 {
423 return !(lhs == rhs);
424 }
425
430 template<class T, class V, class R = V&, class D = std::ptrdiff_t>
432 {
433
434 public:
435 /* type aliases required by C++ for iterators */
436 using iterator_category = std::random_access_iterator_tag;
437 using value_type = typename std::remove_const<V>::type;
438 using difference_type = D;
439 using pointer = V*;
440 using reference = R;
441
475 typedef T DerivedType;
476
480 typedef V Value;
481
485 typedef V* Pointer;
486
490 typedef D DifferenceType;
491
495 typedef R Reference;
496
499 {
500 return static_cast<DerivedType const*>(this)->dereference();
501 }
502
503 Pointer operator->() const
504 {
505 return &(static_cast<const DerivedType *>(this)->dereference());
506 }
507
514 {
515 return static_cast<const DerivedType *>(this)->elementAt(n);
516 }
517
520 {
521 static_cast<DerivedType *>(this)->increment();
522 return *static_cast<DerivedType *>(this);
523 }
524
527 {
528 DerivedType tmp(static_cast<DerivedType const&>(*this));
529 this->operator++();
530 return tmp;
531 }
532
533 DerivedType& operator+=(DifferenceType n)
534 {
535 static_cast<DerivedType *>(this)->advance(n);
536 return *static_cast<DerivedType *>(this);
537 }
538
539 DerivedType operator+(DifferenceType n) const
540 {
541 DerivedType tmp(static_cast<DerivedType const&>(*this));
542 tmp.advance(n);
543 return tmp;
544 }
545
546
549 {
550 static_cast<DerivedType *>(this)->decrement();
551 return *static_cast<DerivedType *>(this);
552 }
553
556 {
557 DerivedType tmp(static_cast<DerivedType const&>(*this));
558 this->operator--();
559 return tmp;
560 }
561
562 DerivedType& operator-=(DifferenceType n)
563 {
564 static_cast<DerivedType *>(this)->advance(-n);
565 return *static_cast<DerivedType *>(this);
566 }
567
568 DerivedType operator-(DifferenceType n) const
569 {
570 DerivedType tmp(static_cast<DerivedType const&>(*this));
571 tmp.advance(-n);
572 return tmp;
573 }
574
575
576 };
577
588 template<class T1, class V1, class R1, class D,
589 class T2, class V2, class R2>
590 inline typename EnableIfInterOperable<T1,T2,bool>::type
593 {
594 if(std::is_convertible<T2,T1>::value)
595 return static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
596 else
597 return static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
598 }
599
610 template<class T1, class V1, class R1, class D,
611 class T2, class V2, class R2>
612 inline typename EnableIfInterOperable<T1,T2,bool>::type
615 {
616 if(std::is_convertible<T2,T1>::value)
617 return !static_cast<const T1&>(lhs).equals(static_cast<const T2&>(rhs));
618 else
619 return !static_cast<const T2&>(rhs).equals(static_cast<const T1&>(lhs));
620 }
621
632 template<class T1, class V1, class R1, class D,
633 class T2, class V2, class R2>
637 {
638 if(std::is_convertible<T2,T1>::value)
639 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>0;
640 else
641 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<0;
642 }
643
644
655 template<class T1, class V1, class R1, class D,
656 class T2, class V2, class R2>
660 {
661 if(std::is_convertible<T2,T1>::value)
662 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))>=0;
663 else
664 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))<=0;
665 }
666
667
678 template<class T1, class V1, class R1, class D,
679 class T2, class V2, class R2>
680 inline typename EnableIfInterOperable<T1,T2,bool>::type
683 {
684 if(std::is_convertible<T2,T1>::value)
685 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<0;
686 else
687 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>0;
688 }
689
700 template<class T1, class V1, class R1, class D,
701 class T2, class V2, class R2>
702 inline typename EnableIfInterOperable<T1,T2,bool>::type
705 {
706 if(std::is_convertible<T2,T1>::value)
707 return static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs))<=0;
708 else
709 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs))>=0;
710 }
711
722 template<class T1, class V1, class R1, class D,
723 class T2, class V2, class R2>
724 inline typename EnableIfInterOperable<T1,T2,D>::type
727 {
728 if(std::is_convertible<T2,T1>::value)
729 return -static_cast<const T1&>(lhs).distanceTo(static_cast<const T2&>(rhs));
730 else
731 return static_cast<const T2&>(rhs).distanceTo(static_cast<const T1&>(lhs));
732 }
733
735}
736#endif
Facade class for stl conformant bidirectional iterators.
Definition: iteratorfacades.hh:272
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:330
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:307
DerivedType & operator--()
Preincrement operator.
Definition: iteratorfacades.hh:357
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:341
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:317
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:327
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:348
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:322
DerivedType operator--(int)
Postincrement operator.
Definition: iteratorfacades.hh:364
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:312
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:139
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:207
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:188
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:193
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:173
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:178
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:214
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:183
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:196
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:432
DerivedType operator--(int)
Postdecrement operator.
Definition: iteratorfacades.hh:555
Reference operator*() const
Dereferencing operator.
Definition: iteratorfacades.hh:498
DerivedType & operator++()
Preincrement operator.
Definition: iteratorfacades.hh:519
D DifferenceType
The type of the difference between two positions.
Definition: iteratorfacades.hh:490
DerivedType & operator--()
Predecrement operator.
Definition: iteratorfacades.hh:548
Reference operator[](DifferenceType n) const
Get the element n positions from the current one.
Definition: iteratorfacades.hh:513
T DerivedType
The type of derived iterator.
Definition: iteratorfacades.hh:475
V * Pointer
The pointer to the Value.
Definition: iteratorfacades.hh:485
DerivedType operator++(int)
Postincrement operator.
Definition: iteratorfacades.hh:526
V Value
The type of value accessed through the iterator.
Definition: iteratorfacades.hh:480
R Reference
The type of the reference to the values accessed.
Definition: iteratorfacades.hh:495
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:401
constexpr decltype(auto) elementAt(Container &&c, Index &&i)
Get element at given position from container.
Definition: hybridutilities.hh:134
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:635
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:681
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:658
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:235
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:703
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:257
Dune namespace.
Definition: alignedallocator.hh:14
Enable typedef if two types are interoperable.
Definition: typetraits.hh:83
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)