arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize > Class Template Reference

#include <arg_router/utility/unsafe_any.hpp>

Public Member Functions

constexpr unsafe_any_t ()=default
 
template<typename T , typename = std::enable_if_t<use_internal_storage<T> && !std::is_same_v<std::decay_t<T>, unsafe_any_t>>>
 unsafe_any_t (T &&value) noexcept
 
template<typename T , typename Allocator = config::allocator<std::decay_t<T>>, typename = std::enable_if_t<!use_internal_storage<T> && !std::is_same_v<std::decay_t<T>, unsafe_any_t>>>
 unsafe_any_t (T &&value, Allocator alloc=Allocator{})
 
 unsafe_any_t (unsafe_any_t &&other) noexcept
 
 unsafe_any_t (const unsafe_any_t &other)
 
unsafe_any_toperator= (unsafe_any_t other) noexcept
 
 ~unsafe_any_t () noexcept
 
bool has_value () const noexcept
 
template<typename T , typename DecayType = std::decay_t<T>>
std::decay_t< T > & get () noexcept
 
template<typename T >
auto get () const noexcept -> std::conditional_t<(sizeof(T)<=sizeof(std::size_t)) &&std::is_copy_constructible_v< T >, std::decay_t< T >, const std::decay_t< T > & >
 

Friends

void swap (unsafe_any_t &a, unsafe_any_t &b) noexcept
 

Detailed Description

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
class arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >

Type erasure type similar to std::any but has no type checking safety features.

Template Parameters
SmallObjectOptimisationSizeSize in bytes of the small object optimisation limit. Holding objects larger will incur heap allocation. Defaults to word size

Definition at line 21 of file unsafe_any.hpp.

Constructor & Destructor Documentation

◆ unsafe_any_t() [1/5]

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
constexpr arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::unsafe_any_t ( )
constexprdefault

Default constructor.

Calling get() will result in undefined behaviour.

◆ unsafe_any_t() [2/5]

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
template<typename T , typename = std::enable_if_t<use_internal_storage<T> && !std::is_same_v<std::decay_t<T>, unsafe_any_t>>>
arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::unsafe_any_t ( T &&  value)
inlinenoexcept

Constructs an unsafe_any_t from value.

This constructor only takes part in overload resolution if T fits inside the internal storage.

Template Parameters
TType to construct from
Parameters
valueValue to initialise from, will move construct if an rvalue is passed in

Definition at line 47 of file unsafe_any.hpp.

◆ unsafe_any_t() [3/5]

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
template<typename T , typename Allocator = config::allocator<std::decay_t<T>>, typename = std::enable_if_t<!use_internal_storage<T> && !std::is_same_v<std::decay_t<T>, unsafe_any_t>>>
arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::unsafe_any_t ( T &&  value,
Allocator  alloc = Allocator{} 
)
inline

Constructs an unsafe_any_t from value.

This constructor only takes part in overload resolution if T does not fit inside the internal storage.

Template Parameters
TType to construct from
AllocatorAllocator type, only used when not using internal storage
Parameters
valueValue to initialise from, will move construct if an rvalue is passed in
allocAllocator instance

Definition at line 77 of file unsafe_any.hpp.

◆ unsafe_any_t() [4/5]

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::unsafe_any_t ( unsafe_any_t< SmallObjectOptimisationSize > &&  other)
inlinenoexcept

Move constructor.

Note
other is left in an empty state (i.e. has_value() returns false).
Parameters
otherInstance to move from

Definition at line 102 of file unsafe_any.hpp.

◆ unsafe_any_t() [5/5]

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::unsafe_any_t ( const unsafe_any_t< SmallObjectOptimisationSize > &  other)
inline

Copy constructor.

Parameters
otherInstance to copy from

Definition at line 108 of file unsafe_any.hpp.

◆ ~unsafe_any_t()

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::~unsafe_any_t ( )
inlinenoexcept

Destructor.

Definition at line 127 of file unsafe_any.hpp.

Member Function Documentation

◆ get() [1/2]

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
template<typename T >
auto arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::get ( ) const -> std::conditional_t<(sizeof(T) <= sizeof(std::size_t)) && std::is_copy_constructible_v<T>, std::decay_t<T>, const std::decay_t<T>&>
inlinenoexcept

Const overload.

Undefined behaviour if T is not the held type.

Template Parameters
TType to return
Returns
A reference to held object if it is larger than std::size_t and copy constructible, otherwise it returns a copy

Definition at line 167 of file unsafe_any.hpp.

◆ get() [2/2]

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
template<typename T , typename DecayType = std::decay_t<T>>
std::decay_t<T>& arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::get ( )
inlinenoexcept

Returns a reference to the held object.

Undefined behaviour if T is not the held type.

Template Parameters
TType to return
Returns
Held object

Definition at line 148 of file unsafe_any.hpp.

◆ has_value()

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
bool arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::has_value ( ) const
inlinenoexcept

Returns true if the any is holding a value.

This is false if the instance has been moved from.

Returns
True if the any is holding a value

Definition at line 139 of file unsafe_any.hpp.

◆ operator=()

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
unsafe_any_t& arg_router::utility::unsafe_any_t< SmallObjectOptimisationSize >::operator= ( unsafe_any_t< SmallObjectOptimisationSize >  other)
inlinenoexcept

Assignment operator.

Parameters
otherInstance to copy from
Returns
Reference to this

Definition at line 119 of file unsafe_any.hpp.

Friends And Related Function Documentation

◆ swap

template<std::size_t SmallObjectOptimisationSize = sizeof(std::size_t)>
void swap ( unsafe_any_t< SmallObjectOptimisationSize > &  a,
unsafe_any_t< SmallObjectOptimisationSize > &  b 
)
friend

Swap function.

Parameters
aFirst instance
bSecond instance

Definition at line 186 of file unsafe_any.hpp.


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