meta  1.4.9
Classes | Public Member Functions | Friends | List of all members
meta::any Class Reference

Meta any object. More...

#include <meta.hpp>

Public Member Functions

 any () noexcept
 Default constructor.
 
template<typename Type , typename... Args>
 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 >
 any (std::reference_wrapper< Type > type)
 Constructs a meta any that holds an unmanaged object. More...
 
 any (handle handle) 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>>, any>>>
 any (Type &&type)
 Constructs a meta any from a given value. More...
 
 any (const any &other)
 Copy constructor. More...
 
 any (any &&other) noexcept
 Move constructor. More...
 
 ~any ()
 Frees the internal storage, whatever it means.
 
template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, any>>>
anyoperator= (Type &&type)
 Assignment operator. More...
 
anyoperator= (const any &other)
 Copy assignment operator. More...
 
anyoperator= (any &&other) noexcept
 Move assignment operator. More...
 
meta::type type () const noexcept
 Returns the meta type of the underlying object. More...
 
const void * data () const noexcept
 Returns an opaque pointer to the contained instance. More...
 
void * data () noexcept
 Returns an opaque pointer to the contained instance. More...
 
template<typename Type >
const Type * try_cast () const noexcept
 Tries to cast an instance to a given type. More...
 
template<typename Type >
Type * try_cast () noexcept
 Tries to cast an instance to a given type. More...
 
template<typename Type >
const Type & cast () const noexcept
 Tries to cast an instance to a given type. More...
 
template<typename Type >
Type & cast () noexcept
 Tries to cast an instance to a given type. More...
 
template<typename Type >
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 noexcept
 Returns false if a container is empty, true otherwise. More...
 
bool operator== (const any &other) const noexcept
 Checks if two containers differ in their content. More...
 

Friends

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

Detailed Description

Meta any object.

TURN_OFF_DOXYGEN A meta any is an opaque container for single values of any type.

This 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.

Definition at line 299 of file meta.hpp.

Constructor & Destructor Documentation

◆ any() [1/6]

template<typename Type , typename... Args>
meta::any::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.

Definition at line 382 of file meta.hpp.

◆ any() [2/6]

template<typename Type >
meta::any::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.

Definition at line 402 of file meta.hpp.

◆ any() [3/6]

meta::any::any ( handle  handle)
inlinenoexcept

Constructs a meta any from a meta handle object.

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

Definition at line 1942 of file meta.hpp.

◆ any() [4/6]

template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, any>>>
meta::any::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.

Definition at line 421 of file meta.hpp.

◆ any() [5/6]

meta::any::any ( const any other)
inline

Copy constructor.

Parameters
otherThe instance to copy from.

Definition at line 429 of file meta.hpp.

◆ any() [6/6]

meta::any::any ( any &&  other)
inlinenoexcept

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.

Definition at line 448 of file meta.hpp.

Member Function Documentation

◆ cast() [1/2]

template<typename Type >
const Type& meta::any::cast ( ) const
inlinenoexcept

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.

Definition at line 542 of file meta.hpp.

◆ cast() [2/2]

template<typename Type >
Type& meta::any::cast ( )
inlinenoexcept

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.

Definition at line 550 of file meta.hpp.

◆ convert() [1/2]

template<typename Type >
any 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.

Definition at line 561 of file meta.hpp.

◆ convert() [2/2]

template<typename Type >
bool 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.

Definition at line 585 of file meta.hpp.

◆ data() [1/2]

const void* meta::any::data ( ) const
inlinenoexcept

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

Definition at line 502 of file meta.hpp.

◆ data() [2/2]

void* meta::any::data ( )
inlinenoexcept

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

Definition at line 507 of file meta.hpp.

◆ emplace()

template<typename Type , typename... Args>
void 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.

Definition at line 606 of file meta.hpp.

◆ operator bool()

meta::any::operator bool ( ) const
inlineexplicitnoexcept

Returns false if a container is empty, true otherwise.

Returns
False if the container is empty, true otherwise.

Definition at line 614 of file meta.hpp.

◆ operator=() [1/3]

template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, any>>>
any& 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.

Definition at line 468 of file meta.hpp.

◆ operator=() [2/3]

any& meta::any::operator= ( const any other)
inline

Copy assignment operator.

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

Definition at line 477 of file meta.hpp.

◆ operator=() [3/3]

any& meta::any::operator= ( any &&  other)
inlinenoexcept

Move assignment operator.

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

Definition at line 486 of file meta.hpp.

◆ operator==()

bool meta::any::operator== ( const any other) const
inlinenoexcept

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.

Definition at line 624 of file meta.hpp.

◆ try_cast() [1/2]

template<typename Type >
const Type* meta::any::try_cast ( ) const
inlinenoexcept

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.

Definition at line 517 of file meta.hpp.

◆ try_cast() [2/2]

template<typename Type >
Type* meta::any::try_cast ( )
inlinenoexcept

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.

Definition at line 523 of file meta.hpp.

◆ type()

meta::type meta::any::type ( ) const
inlinenoexcept

Returns the meta type of the underlying object.

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

Definition at line 1950 of file meta.hpp.

Friends And Related Function Documentation

◆ swap

void swap ( any lhs,
any rhs 
)
friend

Swaps two meta any objects.

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

Definition at line 633 of file meta.hpp.


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