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

Source

Lines 354-359 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

Source

Lines 363-369 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

Source

Lines 373-379 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>(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

Source

Lines 383-386 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 {
    return (data->type() == type_id<Type>() ? static_cast<const Type *>(data->data()) : nullptr);
}

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

Source

Lines 390-394 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 {
    // last attempt to make wrappers for const references return their values
    return (data->type() == type_id<Type>() ? static_cast<Type *>(static_cast<constness_as_t<basic_any<Len, Align>, Type> *>(data)->data()) : nullptr);
}





Add Discussion

Log in to comment