-
#include "tensorstore/util/small_bit_set.h"
-
template <typename T>
class tensorstore::BitIterator; Iterator within a packed bit sequence.
An iterator is represented by a
base
pointer (of typeT*
) to the packed bit storage and a non-negativeoffset
(of typeptrdiff_t
) in bits, and corresponds to bitoffset % kBitsPerBlock
ofbase[offset / kBitsPerBlock]
.Advancing the iterator changes the
offset
while leaving thebase
pointer unchanged. Only two iterators with the samebase
pointer may be compared.- Template Parameters:¶
- typename T¶
The unsigned integer “block” type used to store the packed bits. If
const
-qualified, the iterator cannot be used to modify the sequence.
- Requires:¶
std::is_unsigned_v<T>
.
Types¶
- using pointer = BitIterator<T>;
- using const_pointer = BitIterator<const T>;
Proxy pointer type.
- using difference_type = ptrdiff_t;
Difference type.
- using value_type = bool;
Value type of iterator.
- using iterator_category = std::random_access_iterator_tag;
Iterator category.
Data members¶
- constexpr const ptrdiff_t kBitsPerBlock = sizeof(T) * 8;
Number of bits stored per block of type
T
.
Constructors¶
- constexpr BitIterator();
Constructs an invalid iterator.
- constexpr BitIterator(T* base, ptrdiff_t offset);
Constructs from a base pointer and offset.
- constexpr BitIterator(BitIterator<U> other);
Converts from a non-
const
iterator.
Methods¶
- constexpr BitRef<T> operator*() const;
Returns a proxy reference to the bit referenced by this iterator.
- constexpr BitRef<T> operator[](ptrdiff_t offset) const;
Returns a proxy reference to the bit at the specified
offset
.
Arithmetic operations¶
- BitIterator& operator++();
Pre-increment operator.
- BitIterator& operator--();
Pre-decrement operator.
- BitIterator operator++(int);
Post-increment operator.
- BitIterator operator--(int);
Post-decrement operator.
- friend BitIterator operator+(BitIterator it, ptrdiff_t offset);
- friend BitIterator operator+(ptrdiff_t offset, BitIterator it);
- BitIterator& operator+=(ptrdiff_t x);
Adds an offset to an iterator.
- friend BitIterator operator-(BitIterator it, ptrdiff_t offset);
- BitIterator& operator-=(ptrdiff_t x);
Subtracts an offset from an iterator.
Friend functions¶
- friend constexpr ptrdiff_t operator-(BitIterator a, BitIterator b);
- friend constexpr bool operator==(BitIterator a, BitIterator b);
- friend constexpr bool operator!=(BitIterator a, BitIterator b);
- friend constexpr bool operator<(BitIterator a, BitIterator b);
- friend constexpr bool operator<=(BitIterator a, BitIterator b);
- friend constexpr bool operator>(BitIterator a, BitIterator b);
- friend constexpr bool operator>=(BitIterator a, BitIterator b);
Compares the positions of two iterators.