Class Any#
Defined in File any.h
Class Documentation#
-
class Any#
Managed Any that takes strong reference to a value.
Public Functions
-
inline void reset()#
Reset any to None.
-
inline void swap(Any &other) noexcept#
Swap this Any with another Any.
- Parameters:
other – The other Any
-
inline int32_t type_index() const noexcept#
- Returns:
the internal type index
-
inline Any()#
Default constructor.
-
inline ~Any()#
Destructor.
-
inline Any(const AnyView &other)#
Constructor from another AnyView.
- Parameters:
other – The other AnyView
-
template<typename T, typename = std::enable_if_t<TypeTraits<T>::convert_enabled>>
inline Any(T other)# Constructor from a general type.
- Template Parameters:
T – The value type of the other
-
template<typename T, typename = std::enable_if_t<TypeTraits<T>::storage_enabled || std::is_same_v<T, Any>>>
inline std::optional<T> as() &&# Try to reinterpret the Any as a type T, return std::nullopt if it is not possible.
Note
This function won’t try to 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<TypeTraits<T>::convert_enabled || std::is_same_v<T, Any>>>
inline std::optional<T> as() const &# Try to reinterpret the Any as a type T, return std::nullopt if it is not possible.
Note
This function won’t try to 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, throw an exception if the cast is not possible.
- Template Parameters:
T – The type to cast to.
-
template<typename T, typename = std::enable_if_t<TypeTraits<T>::storage_enabled>>
inline T cast() &&# Cast to a type T, throw an exception if the cast is not possible.
- Template Parameters:
T – The type to cast to.
-
template<typename T, typename = std::enable_if_t<TypeTraits<T>::convert_enabled || std::is_same_v<T, Any>>>
inline std::optional<T> try_cast() const# Try to cast to a type T.
Note
use STL name since it to be more consistent with cast API.
- Template Parameters:
T – The type to cast to.
- Returns:
The casted value, or std::nullopt if the cast is not possible.
-
inline bool same_as(const Any &other) const noexcept#
Check if the two Any are same type and value in shallow comparison.
Friends
- friend struct AnyHash
- friend struct AnyEqual
-
inline void reset()#