EnTT  3.6.0
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 <poly.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 () 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) noexcept
 Constructs a poly from a given value. More...
 
 poly (const poly &other)=default
 Copy constructor. More...
 
 poly (poly &&other) noexcept
 Move constructor. More...
 
polyoperator= (poly other)
 Assignment operator. More...
 
type_info type () const noexcept
 Returns the type of the contained 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 , typename... Args>
void emplace (Args &&... args)
 Replaces the contained object by creating a new instance directly. More...
 
 operator bool () const noexcept
 Returns false if a poly is empty, true otherwise. More...
 
concept_typeoperator-> () noexcept
 Returns a pointer to the underlying concept. More...
 
const concept_typeoperator-> () const 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) noexcept
 Aliasing constructor. More...
 
poly as_ref (const poly &other) 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.

Definition at line 176 of file poly.hpp.

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.

Definition at line 199 of file poly.hpp.

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

Definition at line 210 of file poly.hpp.

◆ 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)
inlinenoexcept

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.

Definition at line 220 of file poly.hpp.

◆ 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)
inlinenoexcept

Move constructor.

Parameters
otherThe instance to move from.

Definition at line 234 of file poly.hpp.

Member Function Documentation

◆ data() [1/2]

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

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

Definition at line 262 of file poly.hpp.

◆ data() [2/2]

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

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

Definition at line 267 of file poly.hpp.

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

Definition at line 278 of file poly.hpp.

◆ operator bool()

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

Returns false if a poly is empty, true otherwise.

Returns
False if the poly is empty, true otherwise.

Definition at line 287 of file poly.hpp.

◆ operator->() [1/2]

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

Returns a pointer to the underlying concept.

Returns
A pointer to the underlying concept.

Definition at line 300 of file poly.hpp.

◆ operator->() [2/2]

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

Returns a pointer to the underlying concept.

Returns
A pointer to the underlying concept.

Definition at line 295 of file poly.hpp.

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

Definition at line 245 of file poly.hpp.

◆ type()

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

Returns the type of the contained object.

Returns
The type of the contained object, if any.

Definition at line 254 of file poly.hpp.

Friends And Related Function Documentation

◆ as_ref [1/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.

Definition at line 328 of file poly.hpp.

◆ as_ref [2/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.

Definition at line 320 of file poly.hpp.

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

Definition at line 309 of file poly.hpp.


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