Class AnyView#
Defined in File any.h
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#
-
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.
Public Static Functions
Friends
- friend class Any
-
inline void reset()#