-
#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 aDataType
in order to support a dynamic element type determined at run time.If
Element
is non-void
, theDataType
is not actually stored, making this object the same size asPointer
.Instances of this type are used by
Array
to 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
ElementPointer
type.
- 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, orElementPointer
type.
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
true
if 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
true
if 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
A
andB
could 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>; StaticDataType
corresponding to the element type ofPointer
, orDataType
if the element type isvoid
.
- class tensorstore::Shared<Element>;
Tag type that represents an
Element
type to be held via anstd::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.
Related Constants¶
-
constexpr bool tensorstore::IsElementTag<T> =
(IsElementType<T> && !IsShared<T>); An ElementTag type is a type
T
orShared<T>
whereT
satisfiesIsElementType<T>
. It specifies a pointer type ofT*
orstd::shared_ptr<T>
, respectively.
-
constexpr bool
tensorstore::IsArrayBasePointerConvertible<SourcePointer,
TargetPointer>; bool
-valued metafunction that evaluates totrue
ifSourcePointer
may be converted toTargetPointer
when used as an array base pointer.
-
constexpr bool
tensorstore::IsElementPointerCastConvertible<Source, Target>; Determine if
Source
andTarget
are instances ofElementPointer
andSource
is (explicitly) convertible toTarget
.
- constexpr bool tensorstore::IsNonVoidArrayBasePointer<T>;
bool
-valued metafunction that evaluates totrue
ifT
isElement*
orstd::shared_ptr<Element>
, whereElement
is non-void
.
- constexpr bool tensorstore::IsElementPointer<T>;
bool
-valued metafunction that evaluates totrue
ifT
is 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-
Shared
ElementPointer
to aSharedElementPointer
that shares ownership of the specifiedowned
pointer, in the same way as thestd::shared_ptr
aliasing 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
ElementPointer
type.