OpenLexocad  27.1
entt::meta_any Class Reference

Opaque container for values of any type. More...

#include <entt.hpp>

Public Member Functions

 meta_any () ENTT_NOEXCEPT
 Default constructor. More...
 
template<typename Type , typename... Args>
 meta_any (std::in_place_type_t< Type >, [[maybe_unused]] Args &&... args)
 Constructs a meta any by directly initializing the new object. More...
 
template<typename Type >
 meta_any (std::reference_wrapper< Type > type)
 Constructs a meta any that holds an unmanaged object. More...
 
 meta_any (meta_handle handle) ENTT_NOEXCEPT
 Constructs a meta any from a meta handle object. More...
 
template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, meta_any>>>
 meta_any (Type &&type)
 Constructs a meta any from a given value. More...
 
 meta_any (const meta_any &other)
 Copy constructor. More...
 
 meta_any (meta_any &&other) ENTT_NOEXCEPT
 Move constructor. More...
 
 ~meta_any ()
 Frees the internal storage, whatever it means. More...
 
template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, meta_any>>>
meta_anyoperator= (Type &&type)
 Assignment operator. More...
 
meta_anyoperator= (const meta_any &other)
 Copy assignment operator. More...
 
meta_anyoperator= (meta_any &&other) ENTT_NOEXCEPT
 Move assignment operator. More...
 
meta_type type () const ENTT_NOEXCEPT
 Returns the meta type of the underlying object. More...
 
const void * data () const ENTT_NOEXCEPT
 Returns an opaque pointer to the contained instance. More...
 
void * data () ENTT_NOEXCEPT
 Returns an opaque pointer to the contained instance. More...
 
template<typename Type >
const Type * try_cast () const ENTT_NOEXCEPT
 Tries to cast an instance to a given type. More...
 
template<typename Type >
Type * try_cast () ENTT_NOEXCEPT
 Tries to cast an instance to a given type. More...
 
template<typename Type >
const Type & cast () const ENTT_NOEXCEPT
 Tries to cast an instance to a given type. More...
 
template<typename Type >
Type & cast () ENTT_NOEXCEPT
 Tries to cast an instance to a given type. More...
 
template<typename Type >
meta_any convert () const
 Tries to convert an instance to a given type and returns it. More...
 
template<typename Type >
bool convert ()
 Tries to convert an instance to a given type. More...
 
template<typename Type , typename... Args>
void emplace (Args &&... args)
 Replaces the contained object by initializing a new instance directly. More...
 
 operator bool () const ENTT_NOEXCEPT
 Returns false if a container is empty, true otherwise. More...
 
bool operator== (const meta_any &other) const ENTT_NOEXCEPT
 Checks if two containers differ in their content. More...
 

Friends

class meta_handle
 A meta handle is allowed to inherit from a meta any. More...
 
void swap (meta_any &lhs, meta_any &rhs) ENTT_NOEXCEPT
 Swaps two meta any objects. More...
 

Detailed Description

Opaque container for values of any type.

TURN_OFF_DOXYGENThis class uses a technique called small buffer optimization (SBO) to completely eliminate the need to allocate memory, where possible.
From the user's point of view, nothing will change, but the elimination of allocations will reduce the jumps in memory and therefore will avoid chasing of pointers. This will greatly improve the use of the cache, thus increasing the overall performance.

Warning
Only copy constructible types are suitable for use with this class. A static assertion will abort the compilation when the type provided isn't copy constructible.

Constructor & Destructor Documentation

◆ meta_any() [1/7]

entt::meta_any::meta_any ( )
inline

Default constructor.

◆ meta_any() [2/7]

template<typename Type , typename... Args>
entt::meta_any::meta_any ( std::in_place_type_t< Type >  ,
[[maybe_unused] ] Args &&...  args 
)
inlineexplicit

Constructs a meta any by directly initializing the new object.

Template Parameters
TypeType of object to use to initialize the container.
ArgsTypes of arguments to use to construct the new instance.
Parameters
argsParameters to use to construct the instance.

◆ meta_any() [3/7]

template<typename Type >
entt::meta_any::meta_any ( std::reference_wrapper< Type >  type)
inlineexplicit

Constructs a meta any that holds an unmanaged object.

Template Parameters
TypeType of object to use to initialize the container.
Parameters
typeAn instance of an object to use to initialize the container.

◆ meta_any() [4/7]

entt::meta_any::meta_any ( meta_handle  handle)
inline

Constructs a meta any from a meta handle object.

Parameters
handleA reference to an object to use to initialize the meta any.

◆ meta_any() [5/7]

template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, meta_any>>>
entt::meta_any::meta_any ( Type &&  type)
inline

Constructs a meta any from a given value.

Template Parameters
TypeType of object to use to initialize the container.
Parameters
typeAn instance of an object to use to initialize the container.

◆ meta_any() [6/7]

entt::meta_any::meta_any ( const meta_any other)
inline

Copy constructor.

Parameters
otherThe instance to copy from.

◆ meta_any() [7/7]

entt::meta_any::meta_any ( meta_any &&  other)
inline

Move constructor.

After meta any move construction, instances that have been moved from are placed in a valid but unspecified state. It's highly discouraged to continue using them.

Parameters
otherThe instance to move from.

◆ ~meta_any()

entt::meta_any::~meta_any ( )
inline

Frees the internal storage, whatever it means.

Member Function Documentation

◆ cast() [1/2]

template<typename Type >
const Type& entt::meta_any::cast ( ) const
inline

Tries to cast an instance to a given type.

The type of the instance must be such that the cast is possible.

Warning
Attempting to perform a cast that isn't viable results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case the cast is not feasible.
Template Parameters
TypeType to which to cast the instance.
Returns
A reference to the contained instance.

◆ cast() [2/2]

template<typename Type >
Type& entt::meta_any::cast ( )
inline

Tries to cast an instance to a given type.

The type of the instance must be such that the cast is possible.

Warning
Attempting to perform a cast that isn't viable results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case the cast is not feasible.
Template Parameters
TypeType to which to cast the instance.
Returns
A reference to the contained instance.

◆ convert() [1/2]

template<typename Type >
meta_any entt::meta_any::convert ( ) const
inline

Tries to convert an instance to a given type and returns it.

Template Parameters
TypeType to which to convert the instance.
Returns
A valid meta any object if the conversion is possible, an invalid one otherwise.

◆ convert() [2/2]

template<typename Type >
bool entt::meta_any::convert ( )
inline

Tries to convert an instance to a given type.

Template Parameters
TypeType to which to convert the instance.
Returns
True if the conversion is possible, false otherwise.

◆ data() [1/2]

const void* entt::meta_any::data ( ) const
inline

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

◆ data() [2/2]

void* entt::meta_any::data ( )
inline

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

◆ emplace()

template<typename Type , typename... Args>
void entt::meta_any::emplace ( Args &&...  args)
inline

Replaces the contained object by initializing a new instance directly.

Template Parameters
TypeType of object to use to initialize the container.
ArgsTypes of arguments to use to construct the new instance.
Parameters
argsParameters to use to construct the instance.

◆ operator bool()

entt::meta_any::operator bool ( ) const
inlineexplicit

Returns false if a container is empty, true otherwise.

Returns
False if the container is empty, true otherwise.

◆ operator=() [1/3]

template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, meta_any>>>
meta_any& entt::meta_any::operator= ( Type &&  type)
inline

Assignment operator.

Template Parameters
TypeType of object to use to initialize the container.
Parameters
typeAn instance of an object to use to initialize the container.
Returns
This meta any object.

◆ operator=() [2/3]

meta_any& entt::meta_any::operator= ( const meta_any other)
inline

Copy assignment operator.

Parameters
otherThe instance to assign.
Returns
This meta any object.

◆ operator=() [3/3]

meta_any& entt::meta_any::operator= ( meta_any &&  other)
inline

Move assignment operator.

Parameters
otherThe instance to assign.
Returns
This meta any object.

◆ operator==()

bool entt::meta_any::operator== ( const meta_any other) const
inline

Checks if two containers differ in their content.

Parameters
otherContainer with which to compare.
Returns
False if the two containers differ in their content, true otherwise.

◆ try_cast() [1/2]

template<typename Type >
const Type* entt::meta_any::try_cast ( ) const
inline

Tries to cast an instance to a given type.

Template Parameters
TypeType to which to cast the instance.
Returns
A (possibly null) pointer to the contained instance.

◆ try_cast() [2/2]

template<typename Type >
Type* entt::meta_any::try_cast ( )
inline

Tries to cast an instance to a given type.

Template Parameters
TypeType to which to cast the instance.
Returns
A (possibly null) pointer to the contained instance.

◆ type()

meta_type entt::meta_any::type ( ) const
inline

Returns the meta type of the underlying object.

Returns
The meta type of the underlying object, if any.

Friends And Related Function Documentation

◆ meta_handle

friend class meta_handle
friend

A meta handle is allowed to inherit from a meta any.

◆ swap

void swap ( meta_any lhs,
meta_any rhs 
)
friend

Swaps two meta any objects.

Parameters
lhsA valid meta any object.
rhsA valid meta any object.

The documentation for this class was generated from the following file: