AutoPas  3.0.0
Loading...
Searching...
No Matches
CellIterator.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <type_traits>
10#include <vector>
11
18template <class StorageType, bool modifiable>
20 public:
25 std::conditional_t<modifiable, typename StorageType::iterator, typename StorageType::const_iterator>;
26
30 using ParticleType = std::remove_pointer_t<typename StorageType::value_type>;
31
35 using difference_type = typename IteratorType::difference_type;
39 using value_type = typename IteratorType::value_type;
43 using pointer = typename IteratorType::pointer;
47 using reference = typename IteratorType::reference;
51 using iterator_category = typename IteratorType::iterator_category;
52
57 explicit CellIterator(IteratorType iterator) : iterator(iterator) {}
58
63 inline std::conditional_t<modifiable, ParticleType &, const ParticleType &> operator*() const {
64 using RetType = ParticleType &;
65 // depending on the cell the iterator points to a particle or pointer
66 // resolve this at compile time
67 if constexpr (std::is_same_v<std::remove_const_t<std::remove_reference_t<RetType>>,
68 std::remove_const_t<std::remove_reference_t<decltype(*iterator)>>>) {
69 return *iterator;
70 } else if constexpr (std::is_same_v<std::remove_const_t<std::remove_reference_t<RetType>>,
71 std::remove_const_t<std::remove_reference_t<decltype(**iterator)>>>) {
72 return **iterator;
73 } else {
74 // trigger compile error that prints the type of *iterator
75 return decltype(*iterator)::thisMemberDoesntExist;
76 }
77 }
78
83 inline std::conditional_t<modifiable, ParticleType *, const ParticleType *> operator->() const {
84 return &operator*();
85 }
86
92 ++iterator;
93 return *this;
94 }
95
101 --iterator;
102 return *this;
103 }
104
110 bool operator==(const CellIterator &rhs) const { return iterator == rhs.iterator; }
116 bool operator!=(const CellIterator &rhs) const { return not(*this == rhs); }
117
123 difference_type operator-(const CellIterator &rhs) const { return iterator - rhs.iterator; }
124
130 bool operator<(const CellIterator &rhs) const { return iterator < rhs; }
131
132 private:
136 IteratorType iterator;
137};
Wraps the iterator of arbitrary cells to provide a common interface.
Definition: CellIterator.h:19
std::conditional_t< modifiable, ParticleType &, const ParticleType & > operator*() const
Dereference operator.
Definition: CellIterator.h:63
typename IteratorType::value_type value_type
Type trait to be compatible with std::iterator.
Definition: CellIterator.h:39
bool operator!=(const CellIterator &rhs) const
Not equality operator.
Definition: CellIterator.h:116
typename IteratorType::reference reference
Type trait to be compatible with std::iterator.
Definition: CellIterator.h:47
bool operator==(const CellIterator &rhs) const
Equality operator.
Definition: CellIterator.h:110
bool operator<(const CellIterator &rhs) const
Comparison operator.
Definition: CellIterator.h:130
CellIterator< StorageType, modifiable > & operator++()
Increment the iterator.
Definition: CellIterator.h:91
CellIterator(IteratorType iterator)
Constructor.
Definition: CellIterator.h:57
difference_type operator-(const CellIterator &rhs) const
Distance between two iterators.
Definition: CellIterator.h:123
CellIterator< StorageType, modifiable > & operator--()
Decrement the iterator.
Definition: CellIterator.h:100
std::remove_pointer_t< typename StorageType::value_type > ParticleType
Type of the Particles in the storage.
Definition: CellIterator.h:30
typename IteratorType::iterator_category iterator_category
Type trait to be compatible with std::iterator.
Definition: CellIterator.h:51
typename IteratorType::difference_type difference_type
Type trait to be compatible with std::iterator.
Definition: CellIterator.h:35
std::conditional_t< modifiable, typename StorageType::iterator, typename StorageType::const_iterator > IteratorType
Type of the wrapped iterator.
Definition: CellIterator.h:25
typename IteratorType::pointer pointer
Type trait to be compatible with std::iterator.
Definition: CellIterator.h:43
std::conditional_t< modifiable, ParticleType *, const ParticleType * > operator->() const
Dereference operator.
Definition: CellIterator.h:83