ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
Acts::AnyBase< SIZE > Class Template Reference

Small opaque type-erased type with configurable small buffer optimization. More...

#include <Acts/Utilities/Any.hpp>

Inheritance diagram for Acts::AnyBase< SIZE >:
[legend]
Collaboration diagram for Acts::AnyBase< SIZE >:
[legend]

Public Member Functions

 AnyBase ()=default
 AnyBase (AnyBase &&other) _ACTS_ANY_NOEXCEPT
 Move constructor.
 AnyBase (const AnyBase &other) _ACTS_ANY_NOEXCEPT
 Copy constructor.
template<typename T, typename... Args>
requires (std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
 AnyBase (std::in_place_type_t< T >, Args &&... args)
 Construct with in-place type construction.
template<typename T>
requires (!std::same_as<std::decay_t<T>, AnyBase<SIZE>> && std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
 AnyBase (T &&value) _ACTS_ANY_NOEXCEPT
 Construct from any value type.
 ~AnyBase ()
template<typename T>
T & as ()
 Get reference to stored value of specified type.
template<typename T>
const T & as () const
 Get const reference to stored value of specified type.
template<typename T, typename... Args>
requires (std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
T & emplace (Args &&... args)
 Construct a new value in place, destroying any existing value.
 operator bool () const
 Check if the AnyBase contains a value.
AnyBaseoperator= (AnyBase &&other) _ACTS_ANY_NOEXCEPT
 Move assignment operator.
AnyBaseoperator= (const AnyBase &other) _ACTS_ANY_NOEXCEPT
 Copy assignment operator.

Detailed Description

template<std::size_t SIZE>
class Acts::AnyBase< SIZE >

Small opaque type-erased type with configurable small buffer optimization.

Note
Type requirements:
  • All stored types must be copy constructible and copy assignable.
  • Types stored locally (sizeof(T) <= SIZE) must also be move constructible and move assignable because local moves use move operations when not trivially movable (trivial moves fall back to buffer copies).
  • Types stored on the heap (sizeof(T) > SIZE) are moved by stealing the pointer, so no move operations are required in that case.
In summary:
  • Local storage: values live inside the internal buffer; moves may invoke move operations or buffer copies; copies use copy operations or buffer copies when trivial.
  • Heap storage: values are allocated on the heap; moves transfer ownership of the pointer; copies allocate and copy-construct the pointee.

Constructor & Destructor Documentation

◆ AnyBase() [1/5]

template<std::size_t SIZE>
template<typename T, typename... Args>
requires (std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
Acts::AnyBase< SIZE >::AnyBase ( std::in_place_type_t< T > ,
Args &&... args )
explicit

Construct with in-place type construction.

Template Parameters
TType to construct
ArgsConstructor argument types
Parameters
argsArguments to forward to T's constructor

◆ AnyBase() [2/5]

template<std::size_t SIZE>
Acts::AnyBase< SIZE >::AnyBase ( )
default

◆ AnyBase() [3/5]

template<std::size_t SIZE>
template<typename T>
requires (!std::same_as<std::decay_t<T>, AnyBase<SIZE>> && std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
Acts::AnyBase< SIZE >::AnyBase ( T && value)
explicit

Construct from any value type.

Template Parameters
TType of the value to store
Parameters
valueValue to store in the Any

◆ ~AnyBase()

template<std::size_t SIZE>
Acts::AnyBase< SIZE >::~AnyBase ( )

◆ AnyBase() [4/5]

template<std::size_t SIZE>
Acts::AnyBase< SIZE >::AnyBase ( const AnyBase< SIZE > & other)

Copy constructor.

Parameters
otherThe AnyBase to copy from

◆ AnyBase() [5/5]

template<std::size_t SIZE>
Acts::AnyBase< SIZE >::AnyBase ( AnyBase< SIZE > && other)

Move constructor.

Parameters
otherThe AnyBase to move from

Member Function Documentation

◆ as() [1/2]

template<std::size_t SIZE>
template<typename T>
T & Acts::AnyBase< SIZE >::as ( )

Get reference to stored value of specified type.

Template Parameters
TType to retrieve (must be exact type, no const/ref)
Returns
Reference to the stored value
Exceptions
std::bad_any_castif stored type doesn't match T

◆ as() [2/2]

template<std::size_t SIZE>
template<typename T>
const T & Acts::AnyBase< SIZE >::as ( ) const

Get const reference to stored value of specified type.

Template Parameters
TType to retrieve (must be exact type, no const/ref)
Returns
Const reference to the stored value
Exceptions
std::bad_any_castif stored type doesn't match T

◆ emplace()

template<std::size_t SIZE>
template<typename T, typename... Args>
requires (std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
T & Acts::AnyBase< SIZE >::emplace ( Args &&... args)

Construct a new value in place, destroying any existing value.

Template Parameters
TType to construct
ArgsConstructor argument types
Parameters
argsArguments to forward to T's constructor
Returns
Reference to the newly constructed value

◆ operator bool()

template<std::size_t SIZE>
Acts::AnyBase< SIZE >::operator bool ( ) const
explicit

Check if the AnyBase contains a value.

Returns
True if a value is stored, false if empty

◆ operator=() [1/2]

template<std::size_t SIZE>
AnyBase & Acts::AnyBase< SIZE >::operator= ( AnyBase< SIZE > && other)

Move assignment operator.

Parameters
otherThe AnyBase to move from
Returns
Reference to this object

◆ operator=() [2/2]

template<std::size_t SIZE>
AnyBase & Acts::AnyBase< SIZE >::operator= ( const AnyBase< SIZE > & other)

Copy assignment operator.

Parameters
otherThe AnyBase to copy from
Returns
Reference to this object