-
#include "tensorstore/util/element_pointer.h" -
template <typename ElementTagType>
class tensorstore::ElementPointer; Pairs an array base pointer (either an
Element*or anstd::shared_ptr<Element>) with aDataTypein order to support a dynamic element type determined at run time.If
Elementis non-void, theDataTypeis not actually stored, making this object the same size asPointer.Instances of this type are used by
Arrayto point to the actual array data.- Template Parameters:¶
Types¶
- using ElementTag = ElementTagType;
Element tag type.
- type Pointer;
Underlying data pointer type, either
Element*orstd::shared_ptr<Element>.
-
using element_type =
typename std::pointer_traits<Pointer>::element_type; - using Element = element_type;
Underlying element type.
Constructors¶
- ElementPointer();
- ElementPointer(std::nullptr_t);
Initializes to a null pointer.
- ElementPointer(Source&& source);
Constructs from a compatible
ElementPointertype.
- explicit ElementPointer(unchecked_t, Source&& source);
Unchecked conversion.
- ElementPointer(SourcePointer&& pointer);
-
ElementPointer(SourcePointer&& pointer,
pointee_dtype_t<SourcePointer> dtype); Constructs from another compatible pointer and optional data type.
Methods¶
- ElementPointer& operator=(Source&& source);
Assigns from a
nullptr, pointer type, orElementPointertype.
Accessors¶
- ByteStridedPointer<Element> byte_strided_pointer() const;
Returns the raw pointer value as a
ByteStridedPointer.
- const Pointer& pointer() const&;
- Pointer& pointer() &;
- Pointer&& pointer() &&;
Returns a reference to the stored pointer.
- explicit operator bool() const;
Returns
data() != nullptr.
Comparison¶
-
friend bool
operator==(const ElementPointer& a, const ElementPointer<B>& b); -
friend bool
operator!=(const ElementPointer& a, const ElementPointer<B>& b); Compares the data pointers and data types.
- friend bool operator==(const ElementPointer& p, std::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
trueif an array ofSource-type elements is implicitly convertible to an array ofDest-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
trueif an array ofSource-type elements is explicitly BUT NOT implicitly convertible to an array ofDest-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
AandBcould refer to the same type, ignoring const.
Related Types¶
-
using tensorstore::pointee_dtype_t<Pointer> =
dtype_t<typename std::pointer_traits<
std::remove_cvref_t<Pointer>>::element_type>; StaticDataTypecorresponding to the element type ofPointer, orDataTypeif the element type isvoid.
- class tensorstore::Shared<Element>;
Tag type that represents an
Elementtype to be held via anstd::shared_ptrrather 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.
Related Constants¶
-
constexpr bool tensorstore::IsElementTag<T> =
(IsElementType<T> && !IsShared<T>); An ElementTag type is a type
TorShared<T>whereTsatisfiesIsElementType<T>. It specifies a pointer type ofT*orstd::shared_ptr<T>, respectively.
-
constexpr bool
tensorstore::IsArrayBasePointerConvertible<SourcePointer,
TargetPointer>; bool-valued metafunction that evaluates totrueifSourcePointermay be converted toTargetPointerwhen used as an array base pointer.
-
constexpr bool
tensorstore::IsElementPointerCastConvertible<Source, Target>; Determine if
SourceandTargetare instances ofElementPointerandSourceis (explicitly) convertible toTarget.
- constexpr bool tensorstore::IsNonVoidArrayBasePointer<T>;
bool-valued metafunction that evaluates totrueifTisElement*orstd::shared_ptr<Element>, whereElementis non-void.
- constexpr bool tensorstore::IsElementPointer<T>;
bool-valued metafunction that evaluates totrueifTis an instance ofElementPointer.
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-
SharedElementPointerto aSharedElementPointerthat shares ownership of the specifiedownedpointer, in the same way as thestd::shared_ptraliasing constructor.
Arithmetic operations¶
- T* tensorstore::AddByteOffset(T* x, Index 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
ElementPointertype.