Clementine
Public Types | Public Member Functions | Friends | List of all members
entt::poly< Concept > Class Template Reference

Static polymorphism made simple and within everyone's reach. More...

#include <entt.hpp>

Inheritance diagram for entt::poly< Concept >:
Inheritance graph
[legend]
Collaboration diagram for entt::poly< Concept >:
Collaboration graph
[legend]

Public Types

using concept_type = typename Concept::template type< poly_base< poly< Concept > >>
 Concept type.
 

Public Member Functions

 poly () ENTT_NOEXCEPT
 Default constructor.
 
template<typename Type , typename... Args>
 poly (std::in_place_type_t< Type >, Args &&... args)
 Constructs a poly by directly initializing the new object. More...
 
template<typename Type >
 poly (std::reference_wrapper< Type > value)
 Constructs a poly that holds an unmanaged object. More...
 
template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, poly>>>
 poly (Type &&value) ENTT_NOEXCEPT
 Constructs a poly from a given value. More...
 
 poly (const poly &other)=default
 Copy constructor. More...
 
 poly (poly &&other) ENTT_NOEXCEPT
 Move constructor. More...
 
polyoperator= (poly other)
 Assignment operator. More...
 
type_info type () const ENTT_NOEXCEPT
 Returns the type of the contained 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 , typename... Args>
void emplace (Args &&... args)
 Replaces the contained object by creating a new instance directly. More...
 
 operator bool () const ENTT_NOEXCEPT
 Returns false if a poly is empty, true otherwise. More...
 
concept_typeoperator-> () ENTT_NOEXCEPT
 Returns a pointer to the underlying concept. More...
 
const concept_typeoperator-> () const ENTT_NOEXCEPT
 Returns a pointer to the underlying concept. More...
 

Friends

struct poly_base< poly< Concept > >
 A poly base is allowed to snoop into a poly object.
 
void swap (poly &lhs, poly &rhs)
 Swaps two poly objects. More...
 
poly as_ref (poly &other) ENTT_NOEXCEPT
 Aliasing constructor. More...
 
poly as_ref (const poly &other) ENTT_NOEXCEPT
 Aliasing constructor. More...
 

Detailed Description

template<typename Concept>
class entt::poly< Concept >

Static polymorphism made simple and within everyone's reach.

Static polymorphism is a very powerful tool in C++, albeit sometimes cumbersome to obtain.
This class aims to make it simple and easy to use.

Note
Both deduced and defined static virtual tables are supported.
Moreover, the poly class template also works with unmanaged objects.
Template Parameters
ConceptConcept descriptor.

Constructor & Destructor Documentation

◆ poly() [1/5]

template<typename Concept >
template<typename Type , typename... Args>
entt::poly< Concept >::poly ( std::in_place_type_t< Type >  ,
Args &&...  args 
)
inlineexplicit

Constructs a poly by directly initializing the new object.

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

◆ poly() [2/5]

template<typename Concept >
template<typename Type >
entt::poly< Concept >::poly ( std::reference_wrapper< Type >  value)
inline

Constructs a poly that holds an unmanaged object.

Template Parameters
TypeType of object to use to initialize the poly.
Parameters
valueAn instance of an object to use to initialize the poly.

◆ poly() [3/5]

template<typename Concept >
template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, poly>>>
entt::poly< Concept >::poly ( Type &&  value)
inline

Constructs a poly from a given value.

Template Parameters
TypeType of object to use to initialize the poly.
Parameters
valueAn instance of an object to use to initialize the poly.

◆ poly() [4/5]

template<typename Concept >
entt::poly< Concept >::poly ( const poly< Concept > &  other)
default

Copy constructor.

Parameters
otherThe instance to copy from.

◆ poly() [5/5]

template<typename Concept >
entt::poly< Concept >::poly ( poly< Concept > &&  other)
inline

Move constructor.

Parameters
otherThe instance to move from.

Member Function Documentation

◆ data() [1/2]

template<typename Concept >
const void* entt::poly< Concept >::data ( ) const
inline

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

◆ data() [2/2]

template<typename Concept >
void* entt::poly< Concept >::data ( )
inline

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

◆ emplace()

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

Replaces the contained object by creating a new instance directly.

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

◆ operator bool()

template<typename Concept >
entt::poly< Concept >::operator bool ( ) const
inlineexplicit

Returns false if a poly is empty, true otherwise.

Returns
False if the poly is empty, true otherwise.

◆ operator->() [1/2]

template<typename Concept >
concept_type* entt::poly< Concept >::operator-> ( )
inline

Returns a pointer to the underlying concept.

Returns
A pointer to the underlying concept.

◆ operator->() [2/2]

template<typename Concept >
const concept_type* entt::poly< Concept >::operator-> ( ) const
inline

Returns a pointer to the underlying concept.

Returns
A pointer to the underlying concept.

◆ operator=()

template<typename Concept >
poly& entt::poly< Concept >::operator= ( poly< Concept >  other)
inline

Assignment operator.

Parameters
otherThe instance to assign from.
Returns
This poly object.

◆ type()

template<typename Concept >
type_info entt::poly< Concept >::type ( ) const
inline

Returns the type of the contained object.

Returns
The type of the contained object, if any.

Friends And Related Function Documentation

◆ as_ref [1/2]

template<typename Concept >
poly as_ref ( poly< Concept > &  other)
friend

Aliasing constructor.

Parameters
otherA reference to an object that isn't necessarily initialized.
Returns
A poly that shares a reference to an unmanaged object.

◆ as_ref [2/2]

template<typename Concept >
poly as_ref ( const poly< Concept > &  other)
friend

Aliasing constructor.

Parameters
otherA reference to an object that isn't necessarily initialized.
Returns
A poly that shares a reference to an unmanaged object.

◆ swap

template<typename Concept >
void swap ( poly< Concept > &  lhs,
poly< Concept > &  rhs 
)
friend

Swaps two poly objects.

Parameters
lhsA valid poly object.
rhsA valid poly object.

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