HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes
tt::polymorphic_optional< BaseType, Capacity > Class Template Reference

#include <ttauri/polymorphic_optional.hpp>

Public Types

using value_type = BaseType
 
using reference = value_type &
 
using const_reference = value_type const &
 
using pointer = value_type *
 
using const_pointer = value_type const *
 

Public Member Functions

 ~polymorphic_optional ()
 Destroy any contained value.
 
 polymorphic_optional (polymorphic_optional const &other)=delete
 
 polymorphic_optional (polymorphic_optional &&other)=delete
 
polymorphic_optionaloperator= (polymorphic_optional const &other)=delete
 
polymorphic_optionaloperator= (polymorphic_optional &&other)=delete
 
constexpr polymorphic_optional () noexcept
 Construct an empty value.
 
template<typename Other >
requires (is_different_v<Other, value_type>)
 polymorphic_optional (Other &&other) noexcept
 Construct an object as value.
 
template<decayed_derived_from< value_type > Other>
polymorphic_optionaloperator= (Other &&other) noexcept
 Assign an object.
 
template<derived_from< value_type > T, typename... Args>
reference emplace (Args &&...args) noexcept
 Construct the contained value in-place.
 
bool has_value () const noexcept
 Check whether the object contains a value.
 
 operator bool () const noexcept
 Check whether the object contains a value.
 
void reset () noexcept
 Destroys any contained value.
 
const_reference value () const &noexcept
 Returns the contained value.
 
reference value () &noexcept
 Returns the contained value.
 
const_reference operator* () const noexcept
 Dereference the contained value.
 
reference operator* () noexcept
 Dereference the contained value.
 
const_pointer operator-> () const noexcept
 Get a pointer to the contained value.
 
pointer operator-> () noexcept
 Get a pointer to the contained value.
 

Static Public Attributes

static constexpr size_t capacity = Capacity
 

Detailed Description

template<typename BaseType, size_t Capacity>
class tt::polymorphic_optional< BaseType, Capacity >

Polymorphic optional.

This optional container can hold an polymorphic value.

If the assigned sub-class is larger than the internal buffer the object will be allocated on the heap.

Template Parameters
BaseTypeThe base type of the polymorphic value.
CapacityThe size in bytes of the internal buffer to store the polymorphic value.

Constructor & Destructor Documentation

◆ ~polymorphic_optional()

template<typename BaseType , size_t Capacity>
tt::polymorphic_optional< BaseType, Capacity >::~polymorphic_optional ( )
inline

Destroy any contained value.

◆ polymorphic_optional() [1/2]

template<typename BaseType , size_t Capacity>
constexpr tt::polymorphic_optional< BaseType, Capacity >::polymorphic_optional ( )
inlineconstexprnoexcept

Construct an empty value.

◆ polymorphic_optional() [2/2]

template<typename BaseType , size_t Capacity>
template<typename Other >
requires (is_different_v<Other, value_type>)
tt::polymorphic_optional< BaseType, Capacity >::polymorphic_optional ( Other && other)
inlinenoexcept

Construct an object as value.

Parameters
otherAn object of a sub-class of the value_type.

Member Function Documentation

◆ emplace()

template<typename BaseType , size_t Capacity>
template<derived_from< value_type > T, typename... Args>
reference tt::polymorphic_optional< BaseType, Capacity >::emplace ( Args &&... args)
inlinenoexcept

Construct the contained value in-place.

Template Parameters
TThe sub-class of value_type to construct.
Parameters
argsThe arguments used to construct the object of type O.
Returns
reference to the constructed object.

◆ has_value()

template<typename BaseType , size_t Capacity>
bool tt::polymorphic_optional< BaseType, Capacity >::has_value ( ) const
inlinenoexcept

Check whether the object contains a value.

Returns
True if the object has a value.

◆ operator bool()

template<typename BaseType , size_t Capacity>
tt::polymorphic_optional< BaseType, Capacity >::operator bool ( ) const
inlinenoexcept

Check whether the object contains a value.

Returns
True if the object has a value.

◆ operator*() [1/2]

template<typename BaseType , size_t Capacity>
const_reference tt::polymorphic_optional< BaseType, Capacity >::operator* ( ) const
inlinenoexcept

Dereference the contained value.

It is undefined behaviour to derefence if this does not contain a value.

Returns
A reference to the contained value.

◆ operator*() [2/2]

template<typename BaseType , size_t Capacity>
reference tt::polymorphic_optional< BaseType, Capacity >::operator* ( )
inlinenoexcept

Dereference the contained value.

It is undefined behaviour to derefence if this does not contain a value.

Returns
A reference to the contained value.

◆ operator->() [1/2]

template<typename BaseType , size_t Capacity>
const_pointer tt::polymorphic_optional< BaseType, Capacity >::operator-> ( ) const
inlinenoexcept

Get a pointer to the contained value.

Returns
A pointer to the contained value, or nullptr if this doe not contain a value.

◆ operator->() [2/2]

template<typename BaseType , size_t Capacity>
pointer tt::polymorphic_optional< BaseType, Capacity >::operator-> ( )
inlinenoexcept

Get a pointer to the contained value.

Returns
A pointer to the contained value, or nullptr if this doe not contain a value.

◆ operator=()

template<typename BaseType , size_t Capacity>
template<decayed_derived_from< value_type > Other>
polymorphic_optional & tt::polymorphic_optional< BaseType, Capacity >::operator= ( Other && other)
inlinenoexcept

Assign an object.

Parameters
otherAn object of a sub-class of the value_type.
Returns
reference to this.

◆ reset()

template<typename BaseType , size_t Capacity>
void tt::polymorphic_optional< BaseType, Capacity >::reset ( )
inlinenoexcept

Destroys any contained value.

◆ value() [1/2]

template<typename BaseType , size_t Capacity>
reference tt::polymorphic_optional< BaseType, Capacity >::value ( ) &
inlinenoexcept

Returns the contained value.

Exceptions
std::bad_optional_accesswhen this does not contain a value.
Returns
A reference to the contained value.

◆ value() [2/2]

template<typename BaseType , size_t Capacity>
const_reference tt::polymorphic_optional< BaseType, Capacity >::value ( ) const &
inlinenoexcept

Returns the contained value.

Exceptions
std::bad_optional_accesswhen this does not contain a value.
Returns
A reference to the contained value.

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