#include "tensorstore/data_type.h"
class tensorstore::DataType;

Run-time representation of a C++ type used as the element type for a multi-dimensional array.

This is a Regular type that is inexpensive to copy (equivalent to a pointer).

In generic code, StaticDataType can be used as a drop-in replacement when the type is known at compile time.

This permits array operations, such as allocation, zero initialization, copying/moving, printing to a string, and comparison to be performed on arrays whose element type is specified at compile time.

Except when allocating new memory, an DataType value is typically paired with a void* pointer to an element of the corresponding type (this pairing is implemented by the ElementPointer class).

A DataType instance corresponding to a type known at compile time may be obtained using dtype_v.

Constructors

constexpr DataType();

Initializes to an invalid data type.

Methods

constexpr bool valid() const;

Returns true if this represents a valid data type.

constexpr std::string_view name() const;

Returns the data type name, e.g. "bool" or "uint32".

constexpr ptrdiff_t size() const;

Returns the size in bytes of the data type.

constexpr ptrdiff_t alignment() const;

Returns the alignment required by the data type.

Friend functions

friend H AbslHashValue(H hDataType x);

Abseil hash support.

friend constexpr bool operator==(DataType aDataType b);
friend constexpr bool operator!=(DataType aDataType b);
friend constexpr bool
operator==(DataType rconst std::type_infotype);
friend constexpr bool
operator!=(DataType rconst std::type_infotype);
friend constexpr bool
operator==(const std::type_infotypeDataType r);
friend constexpr bool
operator!=(const std::type_infotypeDataType r);

Comparison operators.

friend std::ostreamoperator<<(std::ostreamosDataType r);

Prints name() if valid() == true, otherwise prints "<unspecified>".

using tensorstore::CanonicalElementType<T>;

Metafunction that maps an unqualified type T to the equivalent canonical element type, if there is one.

enum class tensorstore::DataTypeConversionFlags;

Specifies traits for the conversion from one data type to another.

enum class tensorstore::EqualityComparisonKind;

Specifies an equality comparison method.

class tensorstore::StaticDataType<T>;

Empty/monostate type that represents a statically known element type.

using tensorstore::dtype_t<T> = std::conditional_t<
    
std::is_void_v<T>,
   
 DataType,
   
 StaticDataType<CanonicalElementType<std::remove_cv_t<T>>>>;

Alias for the StaticDataType representing T if T is not void, or DataType if T is void.

constexpr bool tensorstore::IsElementType<T> =
   
 (!std::is_volatile_v<T> && !std::is_reference_v<T> &&
    
 !std::is_function_v<std::remove_const_t<T>> &&
    
 !std::is_array_v<std::remove_const_t<T>>);

An ElementType is any optionally const-qualified fundamental type (including void), pointer type, member pointer type, class/union type, or enumeration type. A type of void or const void indicates a type-erased element type.

constexpr auto tensorstore::dtype_v<T> = dtype_t<T>();

Data type object representing the data type for T, convertible to DataType.

constexpr bool tensorstore::
    
IsDataTypeConversionSupported<From, To, AdditionalFlags>;

bool-valued metafunction that specifies whether a conversion is allowed from a compile-time data type of From to a compile-time data type of To.

Allocation

enum class tensorstore::ElementInitialization;

Specifies the form of initialization to use when allocating an array.

voidtensorstore::AllocateAndConstruct(
    
ptrdiff_t n,
    
ElementInitialization initialization,
    
DataType r);

Allocates and initializes a contiguous 1-dimensional array of n elements of type r specified at run time.

void tensorstore::DestroyAndFree(ptrdiff_t nDataType rvoidptr);

Frees memory allocated by AllocateAndConsruct.

std::shared_ptr<T> tensorstore::AllocateAndConstructShared(
    
ptrdiff_t n,
    
ElementInitialization initialization = default_init,
    
dtype_t<T> r = dtype_v<T>);

Returns a shared_ptr that manages the memory returned by AllocateAndConstruct.

bool tensorstore::IsPossiblySameDataType(DataType aDataType b);
constexpr bool
tensorstore::IsPossiblySameDataType(StaticDataType<T> a,
                                    
StaticDataType<U> b);

Checks if both data types are equal or at least one is unspecified.

DataType tensorstore::GetDataType(std::string_view id);

Returns the DataType with DataType::name equal to id.