Function any_cast
Summary
#include <src/entt/core/any.hpp>
(1) template <typename Type, std::size_t Len, std::size_t Align>
Type any_cast(const basic_any< Len, Align > &data)
(2) template <typename Type, std::size_t Len, std::size_t Align>
Type any_cast(basic_any< Len, Align > &data)
(3) template <typename Type, std::size_t Len, std::size_t Align>
Type any_cast(basic_any< Len, Align > &&data)
(4) template <typename Type, std::size_t Len, std::size_t Align>
const Type * any_cast(const basic_any< Len, Align > *data)
(5) template <typename Type, std::size_t Len, std::size_t Align>
Type * any_cast(basic_any< Len, Align > *data)
Function overload
Synopsis
#include <src/entt/core/any.hpp>
template <typename Type, std::size_t Len, std::size_t Align>
Type any_cast(const basic_any< Len, Align > &data)
Description
Performs type-safe access to the contained object.
- Template Parameters
Type
- Type to which conversion is required.Len
- Size of the storage reserved for the small buffer optimization.Align
- Alignment requirement.- Parameters
data
- Target any object.- Returns
- The element converted to the requested type.
Mentioned in
- Core Functionalities / Any as in any type
- Runtime Reflection System / Any to the rescue
Source
Lines 414-419 in src/entt/core/any.hpp.
template<typename Type, std::size_t Len, std::size_t Align>
Type any_cast(const basic_any<Len, Align> &data) ENTT_NOEXCEPT {
const auto *const instance = any_cast<std::remove_reference_t<Type>>(&data);
ENTT_ASSERT(instance, "Invalid instance");
return static_cast<Type>(*instance);
}
Synopsis
#include <src/entt/core/any.hpp>
template <typename Type, std::size_t Len, std::size_t Align>
Type any_cast(basic_any< Len, Align > &data)
Description
Performs type-safe access to the contained object.
- Template Parameters
Type
- Type to which conversion is required.Len
- Size of the storage reserved for the small buffer optimization.Align
- Alignment requirement.- Parameters
data
- Target any object.- Returns
- The element converted to the requested type.
Mentioned in
- Core Functionalities / Any as in any type
- Runtime Reflection System / Any to the rescue
Source
Lines 422-428 in src/entt/core/any.hpp.
template<typename Type, std::size_t Len, std::size_t Align>
Type any_cast(basic_any<Len, Align> &data) ENTT_NOEXCEPT {
// forces const on non-reference types to make them work also with wrappers for const references
auto *const instance = any_cast<std::remove_reference_t<const Type>>(&data);
ENTT_ASSERT(instance, "Invalid instance");
return static_cast<Type>(*instance);
}
Synopsis
#include <src/entt/core/any.hpp>
template <typename Type, std::size_t Len, std::size_t Align>
Type any_cast(basic_any< Len, Align > &&data)
Description
Performs type-safe access to the contained object.
- Template Parameters
Type
- Type to which conversion is required.Len
- Size of the storage reserved for the small buffer optimization.Align
- Alignment requirement.- Parameters
data
- Target any object.- Returns
- The element converted to the requested type.
Mentioned in
- Core Functionalities / Any as in any type
- Runtime Reflection System / Any to the rescue
Source
Lines 431-444 in src/entt/core/any.hpp.
template<typename Type, std::size_t Len, std::size_t Align>
Type any_cast(basic_any<Len, Align> &&data) ENTT_NOEXCEPT {
if constexpr(std::is_copy_constructible_v<std::remove_cv_t<std::remove_reference_t<Type>>>) {
if(auto *const instance = any_cast<std::remove_reference_t<Type>>(&data); instance) {
return static_cast<Type>(std::move(*instance));
} else {
return any_cast<Type>(data);
}
} else {
auto *const instance = any_cast<std::remove_reference_t<Type>>(&data);
ENTT_ASSERT(instance, "Invalid instance");
return static_cast<Type>(std::move(*instance));
}
}
Synopsis
#include <src/entt/core/any.hpp>
template <typename Type, std::size_t Len, std::size_t Align>
const Type * any_cast(const basic_any< Len, Align > *data)
Description
Performs type-safe access to the contained object.
- Template Parameters
Type
- Type to which conversion is required.Len
- Size of the storage reserved for the small buffer optimization.Align
- Alignment requirement.- Parameters
data
- Target any object.- Returns
- The element converted to the requested type.
Mentioned in
- Core Functionalities / Any as in any type
- Runtime Reflection System / Any to the rescue
Source
Lines 447-451 in src/entt/core/any.hpp.
template<typename Type, std::size_t Len, std::size_t Align>
const Type *any_cast(const basic_any<Len, Align> *data) ENTT_NOEXCEPT {
const auto &info = type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
return static_cast<const Type *>(data->data(info));
}
Synopsis
#include <src/entt/core/any.hpp>
template <typename Type, std::size_t Len, std::size_t Align>
Type * any_cast(basic_any< Len, Align > *data)
Description
Performs type-safe access to the contained object.
- Template Parameters
Type
- Type to which conversion is required.Len
- Size of the storage reserved for the small buffer optimization.Align
- Alignment requirement.- Parameters
data
- Target any object.- Returns
- The element converted to the requested type.
Mentioned in
- Core Functionalities / Any as in any type
- Runtime Reflection System / Any to the rescue
Source
Lines 454-459 in src/entt/core/any.hpp.
template<typename Type, std::size_t Len, std::size_t Align>
Type *any_cast(basic_any<Len, Align> *data) ENTT_NOEXCEPT {
const auto &info = type_id<std::remove_cv_t<std::remove_reference_t<Type>>>();
// last attempt to make wrappers for const references return their values
return static_cast<Type *>(static_cast<constness_as_t<basic_any<Len, Align>, Type> *>(data)->data(info));
}