EnTT  3.8.1
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.
 

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...
 
 basic_poly (const basic_poly &other)=default
 Copy constructor. More...
 
 basic_poly (basic_poly &&other)
 Move constructor. More...
 
basic_poly & operator= (basic_poly other)
 Assignment operator. More...
 
type_info type () const
 Returns the type of the contained object. 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_type * operator-> ()
 Returns a pointer to the underlying concept. More...
 
const concept_type * operator-> () 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.
 
void swap (basic_poly &lhs, basic_poly &rhs)
 Swaps two poly objects. More...
 

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 181 of file poly.hpp.

Constructor & Destructor Documentation

◆ basic_poly() [1/4]

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 204 of file poly.hpp.

◆ basic_poly() [2/4]

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 215 of file poly.hpp.

◆ basic_poly() [3/4]

template<typename Concept , std::size_t Len, std::size_t Align>
entt::basic_poly< Concept, Len, Align >::basic_poly ( const basic_poly< Concept, Len, Align > &  other)
default

Copy constructor.

Parameters
otherThe instance to copy from.

◆ basic_poly() [4/4]

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

Move constructor.

Parameters
otherThe instance to move from.

Definition at line 229 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 318 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 325 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 262 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 257 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 273 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 286 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 294 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 299 of file poly.hpp.

◆ operator=()

template<typename Concept , std::size_t Len, std::size_t Align>
basic_poly& entt::basic_poly< Concept, Len, Align >::operator= ( basic_poly< Concept, Len, Align >  other)
inline

Assignment operator.

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

Definition at line 240 of file poly.hpp.

◆ type()

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

Returns the type of the contained object.

Returns
The type of the contained object, if any.

Definition at line 249 of file poly.hpp.

Friends And Related Function Documentation

◆ swap

template<typename Concept , std::size_t Len, std::size_t Align>
void swap ( basic_poly< Concept, Len, Align > &  lhs,
basic_poly< Concept, Len, Align > &  rhs 
)
friend

Swaps two poly objects.

Parameters
lhsA valid poly object.
rhsA valid poly object.

Definition at line 308 of file poly.hpp.


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