#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 type T*) to the packed bit storage and a non-negative offset (of type ptrdiff_t) in bits, and corresponds to bit offset % kBitsPerBlock of base[offset / kBitsPerBlock].

Advancing the iterator changes the offset while leaving the base pointer unchanged. Only two iterators with the same base 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 reference = BitRef<T>;
using const_reference = BitRef<const T>;

Proxy reference 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(Tbaseptrdiff_t offset);

Constructs from a base pointer and offset.

constexpr BitIterator(BitIterator<U> other);

Converts from a non-const iterator.

Methods

constexpr Tbase() const;

Returns the base pointer.

constexpr ptrdiff_t offset() const;

Returns the bit offset relative to base.

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

BitIteratoroperator++();

Pre-increment operator.

BitIteratoroperator--();

Pre-decrement operator.

BitIterator operator++(int);

Post-increment operator.

BitIterator operator--(int);

Post-decrement operator.

friend BitIterator operator+(BitIterator itptrdiff_t offset);
friend BitIterator operator+(ptrdiff_t offsetBitIterator it);
BitIteratoroperator+=(ptrdiff_t x);

Adds an offset to an iterator.

friend BitIterator operator-(BitIterator itptrdiff_t offset);
BitIteratoroperator-=(ptrdiff_t x);

Subtracts an offset from an iterator.

Friend functions

friend constexpr ptrdiff_t operator-(BitIterator aBitIterator b);

Returns the distance from b to a.

friend constexpr bool operator==(BitIterator aBitIterator b);
friend constexpr bool operator!=(BitIterator aBitIterator b);
friend constexpr bool operator<(BitIterator aBitIterator b);
friend constexpr bool operator<=(BitIterator aBitIterator b);
friend constexpr bool operator>(BitIterator aBitIterator b);
friend constexpr bool operator>=(BitIterator aBitIterator b);

Compares the positions of two iterators.