KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ki::any Class Reference

A type-safe container of any type. More...

#include <ki_any.h>

Classes

union  Arg
 
struct  Manager_External
 
struct  Manager_Internal
 
union  Storage
 

Public Member Functions

constexpr any () noexcept
 Default constructor, creates an empty object.
 
 any (const any &other)
 Copy constructor, copies the state of other.
 
 any (any &&other) noexcept
 Move constructor, transfer the state from other.
 
template<typename T , typename V = decay_if_not_any<T>, typename Mgr = Manager<V>, std::enable_if_t< std::is_copy_constructible_v< V > &&!is_in_place_type_v< V >, bool > = true>
 any (T &&value)
 Construct with a copy of value as the contained object.
 
template<typename T , typename... Args, typename V = std::decay_t<T>, typename Mgr = Manager<V>, any_constructible_t< V, Args &&... > = false>
 any (std::in_place_type_t< T >, Args &&... args)
 Construct with an object created from args as the contained object.
 
template<typename T , typename U , typename... Args, typename V = std::decay_t<T>, typename Mgr = Manager<V>, any_constructible_t< V, std::initializer_list< U > &, Args &&... > = false>
 any (std::in_place_type_t< T >, std::initializer_list< U > il, Args &&... args)
 Construct with an object created from il and args as the contained object.
 
 ~any ()
 Destructor, calls reset()
 
anyoperator= (const any &rhs)
 Copy the state of another object.
 
anyoperator= (any &&rhs) noexcept
 Move assignment operator.
 
template<typename T >
std::enable_if_t< std::is_copy_constructible_v< decay_if_not_any< T > >, any & > operator= (T &&rhs)
 Store a copy of rhs as the contained object.
 
template<typename T , typename... Args>
any_emplace_t< std::decay_t< T >, Args... > emplace (Args &&... args)
 Emplace with an object created from args as the contained object.
 
template<typename T , typename U , typename... Args>
any_emplace_t< std::decay_t< T >, std::initializer_list< U > &, Args &&... > emplace (std::initializer_list< U > il, Args &&... args)
 Emplace with an object created from il and args as the contained object.
 
void reset () noexcept
 If not empty, destroys the contained object.
 
void swap (any &rhs) noexcept
 Exchange state with another object.
 
bool has_value () const noexcept
 Reports whether there is a contained object or not.
 
const std::type_info & type () const noexcept
 The typeid of the contained object, or typeid(void) if empty.
 

Private Types

enum  Op {
  Op_Access , Op_Get_Type_Info , Op_Clone , Op_Destroy ,
  Op_Xfer
}
 
template<typename T , bool Safe = std::is_nothrow_move_constructible_v<T>, bool Fits = ( sizeof( T ) <= sizeof( Storage ) ) && ( alignof( T ) <= alignof( Storage ) )>
using Use_Internal_Storage = std::integral_constant< bool, Safe &&Fits >
 
template<typename T >
using Manager = std::conditional_t< Use_Internal_Storage< T >::value, Manager_Internal< T >, Manager_External< T > >
 
template<typename T , typename V = std::decay_t<T>>
using decay_if_not_any = std::enable_if_t<!std::is_same_v< V, any >, V >
 
template<typename Res , typename T , typename... Args>
using any_constructible = std::enable_if< std::is_copy_constructible_v< T > &&std::is_constructible_v< T, Args... >, Res >
 
template<typename T , typename... Args>
using any_constructible_t = typename any_constructible< bool, T, Args... >::type
 
template<typename V , typename... Args>
using any_emplace_t = typename any_constructible< V &, V, Args... >::type
 

Private Member Functions

template<typename T , typename... Args, typename Mgr = Manager<T>>
void do_emplace (Args &&... args)
 Emplace with an object created from args as the contained object.
 
template<typename T , typename U , typename... Args, typename Mgr = Manager<T>>
void do_emplace (std::initializer_list< U > il, Args &&... args)
 Emplace with an object created from il and args as the contained object.
 

Private Attributes

void(* m_manager )(Op, const any *, Arg *)
 
Storage m_storage
 

Detailed Description

A type-safe container of any type.

An any object's state is either empty or it stores a contained object of CopyConstructible type.

Definition at line 88 of file ki_any.h.

Member Typedef Documentation

◆ any_constructible

template<typename Res , typename T , typename... Args>
using ki::any::any_constructible = std::enable_if<std::is_copy_constructible_v<T> && std::is_constructible_v<T, Args...>, Res>
private

Definition at line 140 of file ki_any.h.

◆ any_constructible_t

template<typename T , typename... Args>
using ki::any::any_constructible_t = typename any_constructible<bool, T, Args...>::type
private

Definition at line 145 of file ki_any.h.

◆ any_emplace_t

template<typename V , typename... Args>
using ki::any::any_emplace_t = typename any_constructible<V&, V, Args...>::type
private

Definition at line 148 of file ki_any.h.

◆ decay_if_not_any

template<typename T , typename V = std::decay_t<T>>
using ki::any::decay_if_not_any = std::enable_if_t<!std::is_same_v<V, any>, V>
private

Definition at line 119 of file ki_any.h.

◆ Manager

template<typename T >
using ki::any::Manager = std::conditional_t<Use_Internal_Storage<T>::value, Manager_Internal<T>, Manager_External<T> >
private

Definition at line 115 of file ki_any.h.

◆ Use_Internal_Storage

template<typename T , bool Safe = std::is_nothrow_move_constructible_v<T>, bool Fits = ( sizeof( T ) <= sizeof( Storage ) ) && ( alignof( T ) <= alignof( Storage ) )>
using ki::any::Use_Internal_Storage = std::integral_constant<bool, Safe && Fits>
private

Definition at line 106 of file ki_any.h.

Member Enumeration Documentation

◆ Op

enum ki::any::Op
private
Enumerator
Op_Access 
Op_Get_Type_Info 
Op_Clone 
Op_Destroy 
Op_Xfer 

Definition at line 331 of file ki_any.h.

Constructor & Destructor Documentation

◆ any() [1/6]

constexpr ki::any::any ( )
inlineconstexprnoexcept

Default constructor, creates an empty object.

Definition at line 152 of file ki_any.h.

Referenced by operator=().

◆ any() [2/6]

ki::any::any ( const any other)
inline

Copy constructor, copies the state of other.

Definition at line 155 of file ki_any.h.

References has_value(), ki::any::Arg::m_any, m_manager, and Op_Clone.

◆ any() [3/6]

ki::any::any ( any &&  other)
inlinenoexcept

Move constructor, transfer the state from other.

Definition at line 170 of file ki_any.h.

References ki::any::Arg::m_any, m_manager, and Op_Xfer.

◆ any() [4/6]

template<typename T , typename V = decay_if_not_any<T>, typename Mgr = Manager<V>, std::enable_if_t< std::is_copy_constructible_v< V > &&!is_in_place_type_v< V >, bool > = true>
ki::any::any ( T &&  value)
inline

Construct with a copy of value as the contained object.

Definition at line 189 of file ki_any.h.

References m_storage.

◆ any() [5/6]

template<typename T , typename... Args, typename V = std::decay_t<T>, typename Mgr = Manager<V>, any_constructible_t< V, Args &&... > = false>
ki::any::any ( std::in_place_type_t< T >  ,
Args &&...  args 
)
inlineexplicit

Construct with an object created from args as the contained object.

Definition at line 197 of file ki_any.h.

References m_storage.

◆ any() [6/6]

template<typename T , typename U , typename... Args, typename V = std::decay_t<T>, typename Mgr = Manager<V>, any_constructible_t< V, std::initializer_list< U > &, Args &&... > = false>
ki::any::any ( std::in_place_type_t< T >  ,
std::initializer_list< U >  il,
Args &&...  args 
)
inlineexplicit

Construct with an object created from il and args as the contained object.

Definition at line 206 of file ki_any.h.

References m_storage.

◆ ~any()

ki::any::~any ( )
inline

Destructor, calls reset()

Definition at line 213 of file ki_any.h.

References reset().

Member Function Documentation

◆ do_emplace() [1/2]

template<typename T , typename... Args, typename Mgr = Manager<T>>
void ki::any::do_emplace ( Args &&...  args)
inlineprivate

Emplace with an object created from args as the contained object.

Definition at line 123 of file ki_any.h.

References m_manager, m_storage, and reset().

◆ do_emplace() [2/2]

template<typename T , typename U , typename... Args, typename Mgr = Manager<T>>
void ki::any::do_emplace ( std::initializer_list< U >  il,
Args &&...  args 
)
inlineprivate

Emplace with an object created from il and args as the contained object.

Definition at line 132 of file ki_any.h.

References m_manager, m_storage, and reset().

◆ emplace() [1/2]

template<typename T , typename... Args>
any_emplace_t< std::decay_t< T >, Args... > ki::any::emplace ( Args &&...  args)
inline

Emplace with an object created from args as the contained object.

Definition at line 250 of file ki_any.h.

References m_storage.

Referenced by BOOST_AUTO_TEST_CASE().

◆ emplace() [2/2]

template<typename T , typename U , typename... Args>
any_emplace_t< std::decay_t< T >, std::initializer_list< U > &, Args &&... > ki::any::emplace ( std::initializer_list< U >  il,
Args &&...  args 
)
inline

Emplace with an object created from il and args as the contained object.

Definition at line 260 of file ki_any.h.

References m_storage.

◆ has_value()

bool ki::any::has_value ( ) const
inlinenoexcept

Reports whether there is a contained object or not.

Definition at line 308 of file ki_any.h.

References m_manager.

Referenced by any(), BOOST_AUTO_TEST_CASE(), TOOL_MANAGER::doRunAction(), TOOL_ACTION::GetParam(), TOOL_ACTION::MakeEvent(), TOOL_EVENT::Parameter(), reset(), swap(), TOOL_ACTION::TOOL_ACTION(), and type().

◆ operator=() [1/3]

any & ki::any::operator= ( any &&  rhs)
inlinenoexcept

Move assignment operator.

Definition at line 223 of file ki_any.h.

References ki::any::Arg::m_any, m_manager, Op_Xfer, and reset().

◆ operator=() [2/3]

any & ki::any::operator= ( const any rhs)
inline

Copy the state of another object.

Definition at line 216 of file ki_any.h.

References any().

◆ operator=() [3/3]

template<typename T >
std::enable_if_t< std::is_copy_constructible_v< decay_if_not_any< T > >, any & > ki::any::operator= ( T &&  rhs)
inline

Store a copy of rhs as the contained object.

Definition at line 242 of file ki_any.h.

References any().

◆ reset()

void ki::any::reset ( )
inlinenoexcept

If not empty, destroys the contained object.

Definition at line 268 of file ki_any.h.

References has_value(), m_manager, and Op_Destroy.

Referenced by BOOST_AUTO_TEST_CASE(), do_emplace(), operator=(), and ~any().

◆ swap()

void ki::any::swap ( any rhs)
inlinenoexcept

Exchange state with another object.

Definition at line 278 of file ki_any.h.

References empty(), has_value(), ki::any::Arg::m_any, m_manager, and Op_Xfer.

Referenced by BOOST_AUTO_TEST_CASE().

◆ type()

const std::type_info & ki::any::type ( ) const
inlinenoexcept

The typeid of the contained object, or typeid(void) if empty.

Definition at line 312 of file ki_any.h.

References has_value(), m_manager, ki::any::Arg::m_typeinfo, and Op_Get_Type_Info.

Referenced by BOOST_AUTO_TEST_CASE(), TOOL_ACTION::GetParam(), and TOOL_EVENT::Parameter().

Member Data Documentation

◆ m_manager

void(* ki::any::m_manager) (Op, const any *, Arg *)
private

◆ m_storage


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