Function any_cast

Summary

#include <src/entt/core/any.hpp>

(1) template <typename Type>
    Type any_cast(const any &data) noexcept

(2) template <typename Type>
    Type any_cast(any &data) noexcept

(3) template <typename Type>
    Type any_cast(any &&data) noexcept

(4) template <typename Type>
    const Type * any_cast(const any *data) noexcept

(5) template <typename Type>
    Type * any_cast(any *data) noexcept

Function overload

Synopsis

#include <src/entt/core/any.hpp>

template <typename Type>
Type any_cast(const any &data) noexcept

Description

Performs type-safe access to the contained object.

Template Parameters

Type - Type to which conversion is required.

Parameters

data - Target any object.

Returns
The element converted to the requested type.

Mentioned in

Source

Lines 324-329 in src/entt/core/any.hpp.

template<typename Type>
Type any_cast(const any &data) ENTT_NOEXCEPT {
    const auto * const instance = any_cast<std::remove_reference_t<Type>>(&data);
    ENTT_ASSERT(instance);
    return static_cast<Type>(*instance);
}

Synopsis

#include <src/entt/core/any.hpp>

template <typename Type>
Type any_cast(any &data) noexcept

Description

Performs type-safe access to the contained object.

Template Parameters

Type - Type to which conversion is required.

Parameters

data - Target any object.

Returns
The element converted to the requested type.

Mentioned in

Source

Lines 333-339 in src/entt/core/any.hpp.

template<typename Type>
Type any_cast(any &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::conditional_t<std::is_reference_v<Type>, std::remove_reference_t<Type>, const Type>>(&data);
    ENTT_ASSERT(instance);
    return static_cast<Type>(*instance);
}

Synopsis

#include <src/entt/core/any.hpp>

template <typename Type>
Type any_cast(any &&data) noexcept

Description

Performs type-safe access to the contained object.

Template Parameters

Type - Type to which conversion is required.

Parameters

data - Target any object.

Returns
The element converted to the requested type.

Mentioned in

Source

Lines 343-349 in src/entt/core/any.hpp.

template<typename Type>
Type any_cast(any &&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::conditional_t<std::is_reference_v<Type>, std::remove_reference_t<Type>, const Type>>(&data);
    ENTT_ASSERT(instance);
    return static_cast<Type>(std::move(*instance));
}

Synopsis

#include <src/entt/core/any.hpp>

template <typename Type>
const Type * any_cast(const any *data) noexcept

Description

Performs type-safe access to the contained object.

Template Parameters

Type - Type to which conversion is required.

Parameters

data - Target any object.

Returns
The element converted to the requested type.

Mentioned in

Source

Lines 353-356 in src/entt/core/any.hpp.

template<typename Type>
const Type * any_cast(const any *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>
Type * any_cast(any *data) noexcept

Description

Performs type-safe access to the contained object.

Template Parameters

Type - Type to which conversion is required.

Parameters

data - Target any object.

Returns
The element converted to the requested type.

Mentioned in

Source

Lines 360-364 in src/entt/core/any.hpp.

template<typename Type>
Type * any_cast(any *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<any, Type> *>(data)->data()) : nullptr);
}





Add Discussion

Log in to comment