1 #ifndef PROTOZERO_ITERATORS_HPP 2 #define PROTOZERO_ITERATORS_HPP 27 #if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN 38 template <
typename T,
typename P = std::pair<T, T>>
40 #ifdef PROTOZERO_STRICT_API 53 using value_type =
typename std::iterator_traits<T>::value_type;
69 P(std::forward<
iterator>(first_iterator),
70 std::forward<
iterator>(last_iterator)) {
98 constexpr
bool empty() const noexcept {
107 std::size_t
size() const noexcept {
108 return begin().size();
117 protozero_assert(!
empty());
118 return *(this->first);
127 protozero_assert(!
empty());
138 swap(this->first, other.first);
139 swap(this->second, other.second);
150 template <
typename T>
159 template <
typename T>
163 const char* m_data =
nullptr;
166 const char* m_end =
nullptr;
170 using iterator_category = std::forward_iterator_tag;
171 using value_type = T;
172 using difference_type = std::ptrdiff_t;
173 using pointer = value_type*;
174 using reference = value_type&;
191 value_type operator*()
const {
193 std::memcpy(&result, m_data,
sizeof(value_type));
194 #if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN 195 detail::byteswap_inplace(&result);
211 std::size_t
size()
const noexcept {
212 return static_cast<std::size_t
>(m_end - m_data) /
sizeof(T);
216 return m_data == rhs.m_data && m_end == rhs.m_end;
220 return !(*
this == rhs);
229 template <
typename T>
235 const char* m_data =
nullptr;
238 const char* m_end =
nullptr;
242 using iterator_category = std::forward_iterator_tag;
243 using value_type = T;
244 using difference_type = std::ptrdiff_t;
245 using pointer = value_type*;
246 using reference = value_type&;
263 value_type operator*()
const {
264 const char* d = m_data;
279 std::size_t
size()
const noexcept {
283 return static_cast<std::size_t
>(std::count_if(m_data, m_end, [](
char c) {
284 return (static_cast<unsigned char>(c) & 0x80) == 0;
293 return !(*
this == rhs);
302 template <
typename T>
307 using iterator_category = std::forward_iterator_tag;
308 using value_type = T;
309 using difference_type = std::ptrdiff_t;
310 using pointer = value_type*;
311 using reference = value_type&;
329 value_type operator*()
const {
330 const char* d = this->m_data;
349 #endif // PROTOZERO_ITERATORS_HPP constexpr iterator cbegin() const noexcept
Return iterator to beginning of range.
Definition: iterators.hpp:84
typename std::iterator_traits< T >::value_type value_type
The value type of the underlying iterator.
Definition: iterators.hpp:53
constexpr int64_t decode_zigzag64(uint64_t value) noexcept
Definition: varint.hpp:181
Definition: iterators.hpp:160
void swap(iterator_range &other) noexcept
Definition: iterators.hpp:136
constexpr iterator begin() const noexcept
Return iterator to beginning of range.
Definition: iterators.hpp:74
T iterator
The type of the iterators in this range.
Definition: iterators.hpp:50
constexpr iterator end() const noexcept
Return iterator to end of range.
Definition: iterators.hpp:79
Contains macro checks for different configurations.
constexpr iterator_range(iterator &&first_iterator, iterator &&last_iterator)
Definition: iterators.hpp:68
constexpr bool empty() const noexcept
Definition: iterators.hpp:98
void swap(iterator_range< T > &lhs, iterator_range< T > &rhs) noexcept
Definition: iterators.hpp:151
void skip_varint(const char **data, const char *end)
Definition: varint.hpp:112
void drop_front()
Definition: iterators.hpp:126
const char * m_end
Pointer to end iterator position.
Definition: iterators.hpp:238
std::size_t size() const noexcept
Definition: iterators.hpp:107
const char * m_data
Pointer to current iterator position.
Definition: iterators.hpp:235
Contains functions to swap bytes in values (for different endianness).
constexpr iterator_range()
Definition: iterators.hpp:58
Definition: iterators.hpp:303
bool operator==(const data_view &lhs, const data_view &rhs) noexcept
Definition: types.hpp:187
Definition: iterators.hpp:230
bool operator!=(const data_view &lhs, const data_view &rhs) noexcept
Definition: types.hpp:198
Definition: iterators.hpp:39
Contains low-level varint and zigzag encoding and decoding functions.
value_type front() const
Definition: iterators.hpp:116
uint64_t decode_varint(const char **data, const char *end)
Definition: varint.hpp:89
constexpr iterator cend() const noexcept
Return iterator to end of range.
Definition: iterators.hpp:89
All parts of the protozero header-only library are in this namespace.
Definition: byteswap.hpp:24