alpaqa 1.0.0a16
Nonconvex constrained optimization
Loading...
Searching...
No Matches
ringbuffer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <iterator>
5
6namespace alpaqa {
7
8template <class IndexT = size_t>
16/// @related CircularIndices
17/// @note Only valid for two indices in the same range.
18template <class IndexT>
20 return a.zerobased == b.zerobased;
21}
22/// @related CircularIndices
23/// @note Only valid for two indices in the same range.
24template <class IndexT>
28
29template <class IndexT = size_t>
31 using Index = IndexT;
33
34 CircularIndexIterator() : i{0, 0}, max{0} {}
36
39
42 using difference_type = std::ptrdiff_t; // This is required but not used
43 using pointer = void;
44 using iterator_category = std::input_iterator_tag;
45
46 reference operator*() const { return i; }
49 ++i.zerobased;
50 i.circular = i.circular + 1 == max ? Index{0} : i.circular + 1;
51 return *this;
52 }
54 assert(i.zerobased > 0);
55 --i.zerobased;
56 i.circular = i.circular == Index{0} ? max - 1 : i.circular - 1;
57 return *this;
58 }
60 auto r = *this;
61 ++(*this);
62 return r;
63 }
65 auto r = *this;
66 --(*this);
67 return r;
68 }
69};
70
71/// @related CircularIndexIterator
72/// @note Only valid for two indices in the same range.
73template <class IndexT>
76 assert(a.max == b.max);
77 return a.i == b.i;
78}
79/// @related CircularIndexIterator
80/// @note Only valid for two indices in the same range.
81template <class IndexT>
86
87template <class IndexT = size_t>
90 using Index = typename ForwardIterator::Index;
92
97
99
102 using difference_type = std::ptrdiff_t; // This is required but not used
103 using pointer = void;
104 using iterator_category = std::input_iterator_tag;
105
107 auto tmp = forwardit;
108 return *(--tmp);
109 }
111 --forwardit;
112 return *this;
113 }
115 ++forwardit;
116 return *this;
117 }
119 auto r = *this;
120 ++(*this);
121 return r;
122 }
124 auto r = *this;
125 --(*this);
126 return r;
127 }
128};
129
130/// @related ReverseCircularIndexIterator
131/// @note Only valid for two indices in the same range.
132template <class IndexT>
137/// @related ReverseCircularIndexIterator
138/// @note Only valid for two indices in the same range.
139template <class IndexT>
144
145template <class IndexT>
179
180template <class IndexT>
211
212} // namespace alpaqa
iterator begin() const
const_reverse_iterator reverse_iterator
const_iterator cbegin() const
reverse_iterator rbegin() const
iterator end() const
CircularIndices< Index > Indices
const_reverse_iterator crbegin() const
const_iterator cend() const
CircularRange(Index size, Index idx1, Index idx2, Index max)
const_iterator iterator
reverse_iterator rend() const
const_reverse_iterator crend() const
CircularIndexIterator< Index > const_iterator
ReverseCircularIndexIterator< Index > const_reverse_iterator
ReverseCircularRange(const ForwardRange &forwardrange)
typename ForwardRange::iterator reverse_iterator
typename ForwardRange::const_reverse_iterator const_iterator
ReverseCircularRange(Index size, Index idx1, Index idx2, Index max)
const_iterator cbegin() const
reverse_iterator rbegin() const
typename ForwardRange::const_iterator const_reverse_iterator
typename ForwardRange::Indices Indices
const_reverse_iterator crbegin() const
const_iterator cend() const
reverse_iterator rend() const
const_reverse_iterator crend() const
typename ForwardRange::Index Index
typename ForwardRange::reverse_iterator iterator
constexpr const auto inf
Definition config.hpp:98
CircularIndexIterator & operator--()
CircularIndexIterator(Indices i, Index max)
CircularIndexIterator & operator++()
CircularIndexIterator operator++(int)
CircularIndexIterator operator--(int)
CircularIndices< Index > Indices
bool operator!=(CircularIndexIterator< IndexT > a, CircularIndexIterator< IndexT > b)
reference operator*() const
bool operator==(CircularIndexIterator< IndexT > a, CircularIndexIterator< IndexT > b)
std::input_iterator_tag iterator_category
bool operator!=(CircularIndices< IndexT > a, CircularIndices< IndexT > b)
bool operator==(CircularIndices< IndexT > a, CircularIndices< IndexT > b)
CircularIndices(Index zerobased, Index circular)
ReverseCircularIndexIterator operator--(int)
ReverseCircularIndexIterator operator++(int)
bool operator==(ReverseCircularIndexIterator< IndexT > a, ReverseCircularIndexIterator< IndexT > b)
ReverseCircularIndexIterator(Indices i, Index max)
typename ForwardIterator::Indices Indices
ReverseCircularIndexIterator & operator--()
std::input_iterator_tag iterator_category
ReverseCircularIndexIterator & operator++()
typename ForwardIterator::Index Index
bool operator!=(ReverseCircularIndexIterator< IndexT > a, ReverseCircularIndexIterator< IndexT > b)
ReverseCircularIndexIterator(ForwardIterator forwardit)