#include "tensorstore/util/element_pointer.h"
template <typename ElementTagType>
class tensorstore::ElementPointer;

Pairs an array base pointer (either an Element* or an std::shared_ptr<Element>) with a DataType in order to support a dynamic element type determined at run time.

If Element is non-void, the DataType is not actually stored, making this object the same size as Pointer.

Instances of this type are used by Array to point to the actual array data.

Template Parameters:
typename ElementTagType

An ElementTag type that is either Element (to represent unowned array data) or Shared<Element> (to represent array data with shared ownership).

Types

using ElementTag = ElementTagType;

Element tag type.

type Pointer;

Underlying data pointer type, either Element* or std::shared_ptr<Element>.

using element_type =
   
 typename std::pointer_traits<Pointer>::element_type;
using Element = element_type;

Underlying element type.

using DataType = dtype_t<Element>;

Static or dynamic data type representation.

Constructors

ElementPointer();
ElementPointer(std::nullptr_t);

Initializes to a null pointer.

ElementPointer(Source&source);

Constructs from a compatible ElementPointer type.

explicit ElementPointer(unchecked_tSource&source);

Unchecked conversion.

ElementPointer(SourcePointer&pointer);
ElementPointer(SourcePointer&pointer,
               
pointee_dtype_t<SourcePointer> dtype);

Constructs from another compatible pointer and optional data type.

Methods

ElementPointeroperator=(Source&source);

Assigns from a nullptr, pointer type, or ElementPointer type.

Accessors

constexpr DataType dtype() const;

Returns the data type.

Elementdata() const;

Returns the raw pointer value.

ByteStridedPointer<Element> byte_strided_pointer() const;

Returns the raw pointer value as a ByteStridedPointer.

const Pointerpointer() const&;
Pointerpointer() &;
Pointer&pointer() &&;

Returns a reference to the stored pointer.

explicit operator bool() const;

Returns data() != nullptr.

Comparison

friend bool
operator==(const ElementPointeraconst ElementPointer<B>b);
friend bool
operator!=(const ElementPointeraconst ElementPointer<B>b);

Compares the data pointers and data types.

friend bool operator==(const ElementPointerpstd::nullptr_t);

Checks if the data pointer is null.

Metafunctions

constexpr bool
tensorstore::IsElementTypeImplicitlyConvertible<Source, Dest> =
       
 (std::is_const_v<Source> <= std::is_const_v<Dest>) &&
       
 (std::is_same_v<const Source, const Dest> ||
        
 std::is_void_v<Source> < std::is_void_v<Dest>);

Metafunction that evaluates to true if an array of Source-type elements is implicitly convertible to an array of Dest-type elements.

constexpr bool
tensorstore::IsElementTypeOnlyExplicitlyConvertible<Source,
                                                       
 Dest> =
       
 (std::is_void_v<Source> > std::is_void_v<Dest>) &&
       
 (std::is_const_v<Source> <= std::is_const_v<Dest>);

Metafunction that evaluates true if an array of Source-type elements is explicitly BUT NOT implicitly convertible to an array of Dest-type elements.

constexpr bool
tensorstore::IsElementTypeExplicitlyConvertible<Source, Dest> =
       
 (std::is_const_v<Source> <= std::is_const_v<Dest>) &&
       
 (std::is_void_v<Source> || std::is_void_v<Dest> ||
        
 std::is_same_v<const Source, const Dest>);

Metafunction that evaluates to whether an array of Source-type elements is implicitly or explicitly convertible to an array of Dest-type elements.

constexpr bool tensorstore::AreElementTypesCompatible<A, B> =
   
 (std::is_void_v<A> || std::is_void_v<B> ||
    
 std::is_same_v<const A, const B>);

Metafunction that evaluates to whether A and B could refer to the same type, ignoring const.

using tensorstore::pointee_dtype_t<Pointer> =
   
 dtype_t<typename std::pointer_traits<
        
std::remove_cvref_t<Pointer>>::element_type>;

StaticDataType corresponding to the element type of Pointer, or DataType if the element type is void.

class tensorstore::Shared<Element>;

Tag type that represents an Element type to be held via an std::shared_ptr rather than a raw, unowned pointer.

struct tensorstore::ElementTagTraits<T>;

Traits for element tag types.

using tensorstore::PointerElementTag<T>;

Element tag type corresponding to a given pointer type.

using tensorstore::SharedElementPointer<Element> =
   
 ElementPointer<Shared<Element>>;

Represents a pointer to array data with shared ownership.

constexpr bool tensorstore::IsElementTag<T> =
   
 (IsElementType<T> && !IsShared<T>);

An ElementTag type is a type T or Shared<T> where T satisfies IsElementType<T>. It specifies a pointer type of T* or std::shared_ptr<T>, respectively.

constexpr bool
tensorstore::IsArrayBasePointerConvertible<SourcePointer,
                                              
 TargetPointer>;

bool-valued metafunction that evaluates to true if SourcePointer may be converted to TargetPointer when used as an array base pointer.

constexpr bool
tensorstore::IsElementPointerCastConvertible<Source, Target>;

Determine if Source and Target are instances of ElementPointer and Source is (explicitly) convertible to Target.

constexpr bool tensorstore::IsNonVoidArrayBasePointer<T>;

bool-valued metafunction that evaluates to true if T is Element* or std::shared_ptr<Element>, where Element is non-void.

constexpr bool tensorstore::IsElementPointer<T>;

bool-valued metafunction that evaluates to true if T is an instance of ElementPointer.

Ownership conversion

ElementPointer<Shared<Element>>
tensorstore::UnownedToShared(ElementPointer<Element> element_pointer);

Converts a non-Shared ElementPointer to a SharedElementPointer that does not manage ownership.

ElementPointer<Shared<Element>>
tensorstore::UnownedToShared(const std::shared_ptr<T>owned,
                             
ElementPointer<Element> element_pointer);

Converts a non-Shared ElementPointer to a SharedElementPointer that shares ownership of the specified owned pointer, in the same way as the std::shared_ptr aliasing constructor.

Arithmetic operations

Ttensorstore::AddByteOffset(TxIndex byte_offset);

Adds a byte offset to a raw pointer.

std::shared_ptr<T>
tensorstore::AddByteOffset(const std::shared_ptr<T>x,
                           
Index byte_offset);

Adds a byte offset to a shared_ptr.

ElementPointer<ElementTag>
tensorstore::AddByteOffset(const ElementPointer<ElementTag>x,
                           
Index byte_offset);
ElementPointer<ElementTag>
tensorstore::AddByteOffset(ElementPointer<ElementTag>&x,
                           
Index byte_offset);

Adds a byte offset to an ElementPointer type.