EnTT  3.9.0
Public Types | Public Member Functions | Friends | List of all members
entt::basic_poly< Concept, Len, Align > Class Template Reference

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

#include <poly.hpp>

Inheritance diagram for entt::basic_poly< Concept, Len, Align >:
Inheritance graph
[legend]
Collaboration diagram for entt::basic_poly< Concept, Len, Align >:
Collaboration graph
[legend]

Public Types

using concept_type = typename Concept::template type< poly_base< basic_poly > >
 Concept type.
 
using vtable_type = typename poly_vtable< Concept, Len, Align >::type
 Virtual table type.
 

Public Member Functions

 basic_poly ()
 Default constructor.
 
template<typename Type , typename... Args>
 basic_poly (std::in_place_type_t< Type >, Args &&...args)
 Constructs a poly by directly initializing the new object. More...
 
template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, basic_poly>>>
 basic_poly (Type &&value)
 Constructs a poly from a given value. More...
 
const type_infotype () const
 Returns the object type if any, type_id<void>() otherwise. More...
 
const void * data () const
 Returns an opaque pointer to the contained instance. More...
 
void * data ()
 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...
 
void reset ()
 Destroys contained object.
 
 operator bool () const
 Returns false if a poly is empty, true otherwise. More...
 
concept_typeoperator-> ()
 Returns a pointer to the underlying concept. More...
 
const concept_typeoperator-> () const
 Returns a pointer to the underlying concept. More...
 
basic_poly as_ref ()
 Aliasing constructor. More...
 
basic_poly as_ref () const
 Aliasing constructor. More...
 

Friends

struct poly_base< basic_poly >
 A poly base is allowed to snoop into a poly object.
 

Detailed Description

template<typename Concept, std::size_t Len, std::size_t Align>
class entt::basic_poly< Concept, Len, Align >

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.
LenSize of the storage reserved for the small buffer optimization.
AlignOptional alignment requirement.

Definition at line 192 of file poly.hpp.

Constructor & Destructor Documentation

◆ basic_poly() [1/2]

template<typename Concept , std::size_t Len, std::size_t Align>
template<typename Type , typename... Args>
entt::basic_poly< Concept, Len, Align >::basic_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 214 of file poly.hpp.

◆ basic_poly() [2/2]

template<typename Concept , std::size_t Len, std::size_t Align>
template<typename Type , typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, basic_poly>>>
entt::basic_poly< Concept, Len, Align >::basic_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.

Definition at line 224 of file poly.hpp.

Member Function Documentation

◆ as_ref() [1/2]

template<typename Concept , std::size_t Len, std::size_t Align>
basic_poly entt::basic_poly< Concept, Len, Align >::as_ref ( )
inline

Aliasing constructor.

Returns
A poly that shares a reference to an unmanaged object.

Definition at line 291 of file poly.hpp.

◆ as_ref() [2/2]

template<typename Concept , std::size_t Len, std::size_t Align>
basic_poly entt::basic_poly< Concept, Len, Align >::as_ref ( ) const
inline

Aliasing constructor.

Returns
A poly that shares a reference to an unmanaged object.

Definition at line 299 of file poly.hpp.

◆ data() [1/2]

template<typename Concept , std::size_t Len, std::size_t Align>
void* entt::basic_poly< Concept, Len, Align >::data ( )
inline

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

Definition at line 244 of file poly.hpp.

◆ data() [2/2]

template<typename Concept , std::size_t Len, std::size_t Align>
const void* entt::basic_poly< Concept, Len, Align >::data ( ) const
inline

Returns an opaque pointer to the contained instance.

Returns
An opaque pointer the contained instance, if any.

Definition at line 239 of file poly.hpp.

◆ emplace()

template<typename Concept , std::size_t Len, std::size_t Align>
template<typename Type , typename... Args>
void entt::basic_poly< Concept, Len, Align >::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 255 of file poly.hpp.

◆ operator bool()

template<typename Concept , std::size_t Len, std::size_t Align>
entt::basic_poly< Concept, Len, Align >::operator bool ( ) const
inlineexplicit

Returns false if a poly is empty, true otherwise.

Returns
False if the poly is empty, true otherwise.

Definition at line 270 of file poly.hpp.

◆ operator->() [1/2]

template<typename Concept , std::size_t Len, std::size_t Align>
concept_type* entt::basic_poly< Concept, Len, Align >::operator-> ( )
inline

Returns a pointer to the underlying concept.

Returns
A pointer to the underlying concept.

Definition at line 278 of file poly.hpp.

◆ operator->() [2/2]

template<typename Concept , std::size_t Len, std::size_t Align>
const concept_type* entt::basic_poly< Concept, Len, Align >::operator-> ( ) const
inline

Returns a pointer to the underlying concept.

Returns
A pointer to the underlying concept.

Definition at line 283 of file poly.hpp.

◆ type()

template<typename Concept , std::size_t Len, std::size_t Align>
const type_info& entt::basic_poly< Concept, Len, Align >::type ( ) const
inline

Returns the object type if any, type_id<void>() otherwise.

Returns
The object type if any, type_id<void>() otherwise.

Definition at line 231 of file poly.hpp.


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