#include "tensorstore/util/byte_strided_pointer.h"
template <typename T>
class tensorstore::ByteStridedPointer;

Wrapper type for a raw pointer for which pointer arithmetic operates with a stride of 1 byte, rather than a stride of sizeof(T) bytes.

If the run-time type of the pointee is U, all byte offsets used for arithmetic MUST be a multiple of alignof(U).

Template Parameters:
typename T

The (possibly const-qualified) type of the pointee. It may be void or const void to indicate that the type is not known at compile time.

Types

using element_type = T;

Pointee type.

using difference_type = ptrdiff_t;

Pointer difference type, in bytes.

Data members

constexpr const size_t alignment =
   
 alignof(std::conditional_t<std::is_void_v<T>, char, T>);

Alignment required by T, or 1 if T is void.

Constructors

ByteStridedPointer();

Default initialization, leaves the wrapped raw pointer in an uninitialized state.

ByteStridedPointer(Uvalue);
explicit ByteStridedPointer(Uvalue);

Constructs from a compatible raw pointer.

ByteStridedPointer(ByteStridedPointer<U> value);
explicit ByteStridedPointer(ByteStridedPointer<U> value);

Converts from a compatible ByteStridedPointer type.

Accessors

Tget() const;

Converts to a raw pointer.

Toperator->() const;

Enables member access to the pointee.

Uoperator*() const;

Dereferences the raw pointer.

operator T*() const;
explicit operator U*() const;

Converts to a raw pointer.

Arithmetic operations

ByteStridedPointeroperator+=(Integer byte_offset);

Increments the raw pointer by byte_offset bytes.

ByteStridedPointeroperator-=(Integer byte_offset);

Decrements the raw pointer by byte_offset bytes.

Toperator[](Integer byte_offset) const;

Returns a reference to the element starting at the specified byte_offset relative to get().

friend ptrdiff_t
operator-(ByteStridedPointer<T> aByteStridedPointer<U> b);

Computes the byte offset between two pointers.

friend ByteStridedPointer<T>
operator+(ByteStridedPointer<T> ptrInteger byte_offset);
friend ByteStridedPointer<T>
operator+(Integer byte_offsetByteStridedPointer<T> ptr);

Adds a byte offset to a pointer.

friend ByteStridedPointer<T>
operator-(ByteStridedPointer<T> ptrInteger byte_offset);

Subtracts a byte offset from a pointer.