vecmem 1.14.0
Loading...
Searching...
No Matches
reverse_iterator.ipp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2021 CERN for the benefit of the ACTS project
4 *
5 * Mozilla Public License Version 2.0
6 */
7#pragma once
8
9// Local include(s).
10#include "vecmem/utils/types.hpp"
11
12namespace vecmem {
13namespace details {
14
15template <typename Iterator>
17 : m_current() {}
18
19template <typename Iterator>
22 : m_current(itr) {}
23
24template <typename Iterator>
26 const reverse_iterator& parent)
27 : m_current(parent.m_current) {}
28
29template <typename Iterator>
30template <typename T>
32 const reverse_iterator<T>& parent)
33 : m_current(parent.base()) {}
34
35template <typename Iterator>
36VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>&
38
39 // Avoid a self-assignment.
40 if (this == &rhs) {
41 return *this;
42 }
43
44 // Copy the forward iterator from the other object.
45 m_current = rhs.m_current;
46
47 // Return this object.
48 return *this;
49}
50
51template <typename Iterator>
52VECMEM_HOST_AND_DEVICE typename reverse_iterator<Iterator>::iterator_type
54
55 return m_current;
56}
57
58template <typename Iterator>
59VECMEM_HOST_AND_DEVICE typename reverse_iterator<Iterator>::reference
61
62 iterator_type tmp = m_current;
63 return *(--tmp);
64}
65
66template <typename Iterator>
67VECMEM_HOST_AND_DEVICE typename reverse_iterator<Iterator>::pointer
69
70 iterator_type tmp = m_current;
71 return to_pointer(--tmp);
72}
73
74template <typename Iterator>
75VECMEM_HOST_AND_DEVICE typename reverse_iterator<Iterator>::reference
77
78 return *(*this + n);
79}
80
81template <typename Iterator>
82VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>&
84
85 --m_current;
86 return *this;
87}
88
89template <typename Iterator>
90VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>
92
93 reverse_iterator tmp = *this;
94 --m_current;
95 return tmp;
96}
97
98template <typename Iterator>
99VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>&
101
102 ++m_current;
103 return *this;
104}
105
106template <typename Iterator>
107VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>
109
110 reverse_iterator tmp = *this;
111 ++m_current;
112 return tmp;
113}
114
115template <typename Iterator>
116VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>
121
122template <typename Iterator>
123VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>&
125
126 m_current -= n;
127 return *this;
128}
129
130template <typename Iterator>
131VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>
136
137template <typename Iterator>
138VECMEM_HOST_AND_DEVICE reverse_iterator<Iterator>&
140
141 m_current += n;
142 return *this;
143}
144
145template <typename Iterator>
146template <typename T>
147VECMEM_HOST_AND_DEVICE T* reverse_iterator<Iterator>::to_pointer(T* ptr) {
148
149 return ptr;
150}
151
152template <typename Iterator>
153template <typename T>
154VECMEM_HOST_AND_DEVICE typename reverse_iterator<Iterator>::pointer
155reverse_iterator<Iterator>::to_pointer(T itr) {
156
157 return itr.operator->();
158}
159
160template <typename T1, typename T2>
161VECMEM_HOST_AND_DEVICE bool operator==(const reverse_iterator<T1>& itr1,
162 const reverse_iterator<T2>& itr2) {
163
164 return (itr1.base() == itr2.base());
165}
166
167template <typename T1, typename T2>
168VECMEM_HOST_AND_DEVICE bool operator!=(const reverse_iterator<T1>& itr1,
169 const reverse_iterator<T2>& itr2) {
170
171 return !(itr1 == itr2);
172}
173
174} // namespace details
175} // namespace vecmem
Type mimicking std::reverse_iterator.
Definition reverse_iterator.hpp:25
VECMEM_HOST_AND_DEVICE reverse_iterator & operator--()
Increment the underlying iterator (with '–' as a prefix)
Definition reverse_iterator.ipp:100
std::iterator_traits< iterator_type >::pointer pointer
Pointer type to the underlying value.
Definition reverse_iterator.hpp:39
Iterator iterator_type
Type of the forward iterator, being wrapped.
Definition reverse_iterator.hpp:32
VECMEM_HOST_AND_DEVICE reverse_iterator & operator-=(difference_type n)
Increment the underlying iterator by a specific value.
Definition reverse_iterator.ipp:139
VECMEM_HOST_AND_DEVICE reverse_iterator & operator=(const reverse_iterator &rhs)
Copy assignment operator.
Definition reverse_iterator.ipp:37
VECMEM_HOST_AND_DEVICE pointer operator->() const
Use the iterator as a pointer.
Definition reverse_iterator.ipp:68
std::iterator_traits< iterator_type >::reference reference
Reference type to the underlying value.
Definition reverse_iterator.hpp:41
VECMEM_HOST_AND_DEVICE reverse_iterator & operator+=(difference_type n)
Decrement the underlying iterator by a specific value.
Definition reverse_iterator.ipp:124
VECMEM_HOST_AND_DEVICE reverse_iterator & operator++()
Decrement the underlying iterator (with '++' as a prefix)
Definition reverse_iterator.ipp:83
VECMEM_HOST_AND_DEVICE iterator_type base() const
Access the base/forward iterator.
Definition reverse_iterator.ipp:53
std::iterator_traits< iterator_type >::difference_type difference_type
(Pointer) Difference type
Definition reverse_iterator.hpp:37
VECMEM_HOST_AND_DEVICE reverse_iterator()
Default constructor.
Definition reverse_iterator.ipp:16
VECMEM_HOST_AND_DEVICE reverse_iterator operator-(difference_type n) const
Increment the underlying iterator by a specific value.
Definition reverse_iterator.ipp:132
VECMEM_HOST_AND_DEVICE reference operator[](difference_type n) const
Return the value at a specific offset.
Definition reverse_iterator.ipp:76
VECMEM_HOST_AND_DEVICE reference operator*() const
De-reference the iterator.
Definition reverse_iterator.ipp:60
VECMEM_HOST_AND_DEVICE reverse_iterator operator+(difference_type n) const
Decrement the underlying iterator by a specific value.
Definition reverse_iterator.ipp:117
VECMEM_HOST_AND_DEVICE bool operator==(const reverse_iterator< T1 > &itr1, const reverse_iterator< T2 > &itr2)
Comparison operator for reverse iterators.
Definition reverse_iterator.ipp:161
VECMEM_HOST_AND_DEVICE bool operator!=(const reverse_iterator< T1 > &itr1, const reverse_iterator< T2 > &itr2)
Comparison operator for reverse iterators.
Definition reverse_iterator.ipp:168
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35