1 #ifndef PROTOZERO_ITERATORS_HPP 2 #define PROTOZERO_ITERATORS_HPP 26 #if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN 37 inline void copy_or_byteswap(
const char* src,
void* dest) noexcept {
38 #if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN 39 std::memcpy(dest, src, N);
41 byteswap<N>(src,
reinterpret_cast<char*
>(dest));
52 template <
typename T,
typename P = std::pair<T, T>>
54 #ifdef PROTOZERO_STRICT_API 67 using value_type =
typename std::iterator_traits<T>::value_type;
83 P(std::forward<
iterator>(first_iterator),
84 std::forward<
iterator>(last_iterator)) {
108 constexpr std::size_t
empty() const noexcept {
109 return begin() == end();
118 protozero_assert(!empty());
119 return *(this->first);
128 protozero_assert(!empty());
139 swap(this->first, other.first);
140 swap(this->second, other.second);
151 template <
typename T>
156 #ifdef PROTOZERO_USE_BARE_POINTER_FOR_PACKED_FIXED 158 template <
typename T>
167 template <
typename T>
170 reinterpret_cast<const T*>(last)};
179 template <
typename T>
190 using iterator_category = std::forward_iterator_tag;
191 using value_type = T;
192 using difference_type = std::ptrdiff_t;
193 using pointer = value_type*;
194 using reference = value_type&;
214 value_type operator*()
const {
216 detail::copy_or_byteswap<sizeof(value_type)>(m_data , &result);
221 m_data +=
sizeof(value_type);
232 return m_data == rhs.m_data && m_end == rhs.m_end;
236 return !(*
this == rhs);
247 template <
typename T>
259 template <
typename T>
272 using iterator_category = std::forward_iterator_tag;
273 using value_type = T;
274 using difference_type = std::ptrdiff_t;
275 using pointer = value_type*;
276 using reference = value_type&;
296 value_type operator*()
const {
297 const char* d = m_data;
317 return !(*
this == rhs);
326 template <
typename T>
331 using iterator_category = std::forward_iterator_tag;
332 using value_type = T;
333 using difference_type = std::ptrdiff_t;
334 using pointer = value_type*;
335 using reference = value_type&;
353 value_type operator*()
const {
354 const char* d = this->m_data;
373 #endif // PROTOZERO_ITERATORS_HPP constexpr iterator cbegin() const noexcept
Return iterator to beginning of range.
Definition: iterators.hpp:98
typename std::iterator_traits< T >::value_type value_type
The value type of the underlying iterator.
Definition: iterators.hpp:67
Definition: iterators.hpp:180
void swap(iterator_range &other) noexcept
Definition: iterators.hpp:137
constexpr iterator begin() const noexcept
Return iterator to beginning of range.
Definition: iterators.hpp:88
T iterator
The type of the iterators in this range.
Definition: iterators.hpp:64
constexpr iterator end() const noexcept
Return iterator to end of range.
Definition: iterators.hpp:93
iterator_range< const_fixed_iterator< T > > create_fixed_iterator_range(const char *first, const char *last)
Definition: iterators.hpp:248
Contains macro checks for different configurations.
bool operator!=(data_view &lhs, data_view &rhs) noexcept
Definition: types.hpp:180
constexpr std::size_t empty() const noexcept
Return true if this range is empty.
Definition: iterators.hpp:108
constexpr iterator_range(iterator &&first_iterator, iterator &&last_iterator)
Definition: iterators.hpp:82
void swap(iterator_range< T > &lhs, iterator_range< T > &rhs) noexcept
Definition: iterators.hpp:152
void skip_varint(const char **data, const char *end)
Definition: varint.hpp:112
void drop_front()
Definition: iterators.hpp:127
const char * m_end
Pointer to end iterator position.
Definition: iterators.hpp:268
const char * m_data
Pointer to current iterator position.
Definition: iterators.hpp:265
Contains functions to swap bytes in values (for different endianness).
constexpr iterator_range()
Definition: iterators.hpp:72
Definition: iterators.hpp:327
Definition: iterators.hpp:260
Definition: iterators.hpp:53
Contains low-level varint and zigzag encoding and decoding functions.
bool operator==(data_view &lhs, data_view &rhs) noexcept
Definition: types.hpp:169
value_type front() const
Definition: iterators.hpp:117
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:103
int64_t decode_zigzag64(uint64_t value) noexcept
Definition: varint.hpp:181
All parts of the protozero header-only library are in this namespace.
Definition: byteswap.hpp:24