Class AnyView#

Class Documentation#

class AnyView#

AnyView allows us to take un-managed reference view of any value.

Public Functions

inline void reset()#

Reset any view to None.

inline void swap(AnyView &other) noexcept#

Swap this AnyView with another AnyView.

Parameters:

other – The other AnyView

inline int32_t type_index() const noexcept#
Returns:

the internal type index

inline AnyView()#

Default constructor.

~AnyView() = default#
AnyView(const AnyView&) = default#

Copy constructor.

inline AnyView(AnyView &&other)#

Move constructor.

template<typename T, typename = std::enable_if_t<TypeTraits<T>::convert_enabled>>
inline AnyView(const T &other)#

Constructor from a general type.

Template Parameters:

T – The type to convert from.

Parameters:

other – The value to convert from.

template<typename T, typename = std::enable_if_t<TypeTraits<T>::convert_enabled>>
inline std::optional<T> as() const#

Try to see if we can reinterpret the AnyView to as T object.

Note

This function won’t try run type conversion (use try_cast for that purpose).

Template Parameters:

T – The type to cast to.

Returns:

The casted value, or std::nullopt if the cast is not possible.

template<typename T, typename = std::enable_if_t<std::is_base_of_v<Object, T>>>
inline const T *as() const#

Shortcut of as Object to cast to a const pointer when T is an Object.

Template Parameters:

T – The object type.

Returns:

The requested pointer, returns nullptr if type mismatches.

template<typename T, typename = std::enable_if_t<TypeTraits<T>::convert_enabled>>
inline T cast() const#

Cast to a type T.

Template Parameters:

T – The type to cast to.

Returns:

The casted value, or throws an exception if the cast is not possible.

template<typename T, typename = std::enable_if_t<TypeTraits<T>::convert_enabled>>
inline std::optional<T> try_cast() const#

Try to cast to a type T, return std::nullopt if the cast is not possible.

Template Parameters:

T – The type to cast to.

Returns:

The casted value, or std::nullopt if the cast is not possible.

inline std::string GetTypeKey() const#

Get the type key of the Any.

Returns:

The type key of the Any

inline TVMFFIAny CopyToTVMFFIAny() const#

Note

This function is used only for testing purposes.

Returns:

The underlying supporting data of any view

Public Static Functions

static inline AnyView CopyFromTVMFFIAny(TVMFFIAny data)#
Parameters:

data – the underlying ffi data.

Returns:

Create an AnyView from TVMFFIAny

Protected Attributes

TVMFFIAny data_#

The underlying backing data of the any object.

Friends

friend class Any