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

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

#include <Acts/Utilities/Any.hpp>

Inheritance diagram for Acts::AnyBase< sb_size, copyable >:
[legend]
Collaboration diagram for Acts::AnyBase< sb_size, copyable >:
[legend]

Public Member Functions

 AnyBase (AnyBase &&other) noexcept(detail::kAnyNoexcept)
 Move constructor.
 AnyBase (const AnyBase &)=delete
 Copy constructor deleted when copyable is false (move-only variant).
 AnyBase (const AnyBase &other) noexcept(detail::kAnyNoexcept)
 Copy constructor (only when copyable is true).
template<typename T, typename... Args>
requires (isStorable<std::decay_t<T>>())
 AnyBase (std::in_place_type_t< T >, Args &&... args)
 Construct with in-place type construction.
template<typename T>
requires (isStorable<std::decay_t<T>>())
 AnyBase (T &&value) noexcept(detail::kAnyNoexcept)
 Construct from any value type.
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>
T * asPtr ()
 Get pointer to stored value of specified type.
template<typename T>
const T * asPtr () const
 Get const pointer to stored value of specified type.
template<typename T, typename... Args>
requires (isStorable<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) noexcept(detail::kAnyNoexcept)
 Move assignment operator.
AnyBaseoperator= (const AnyBase &)=delete
 Copy assignment deleted when copyable is false (move-only variant).
AnyBaseoperator= (const AnyBase &other) noexcept(detail::kAnyNoexcept)
 Copy assignment operator (only when copyable is true).
template<typename T>
take ()
 Move the stored value out.
const std::type_info * typeInfo () const
 Type info of the stored value.

Detailed Description

template<std::size_t sb_size, bool copyable = true>
class Acts::AnyBase< sb_size, copyable >

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

Template Parameters
sb_sizeSize of the internal buffer for small buffer optimization
copyableIf true, stored types must be copyable and AnyBase is copyable. If false, move-only types are allowed and AnyBase is move-only (copy constructor and copy assignment are deleted).
Note
Type requirements when copyable is true:
  • All stored types must be copy constructible and copy assignable.
  • Types stored locally (sizeof(T) <= sb_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) > sb_size) are moved by stealing the pointer, so no move operations are required in that case.
Type requirements when copyable is false:
  • All stored types must be move constructible.
  • Types stored locally must also be move assignable.
  • Heap-allocated types only need move constructible (pointer steal).
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/4]

template<std::size_t sb_size, bool copyable = true>
template<typename T, typename... Args>
requires (isStorable<std::decay_t<T>>())
Acts::AnyBase< sb_size, copyable >::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/4]

template<std::size_t sb_size, bool copyable = true>
template<typename T>
requires (isStorable<std::decay_t<T>>())
Acts::AnyBase< sb_size, copyable >::AnyBase ( T && value)
explicitnoexcept

Construct from any value type.

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

◆ AnyBase() [3/4]

template<std::size_t sb_size, bool copyable = true>
Acts::AnyBase< sb_size, copyable >::AnyBase ( const AnyBase< sb_size, copyable > & other)
noexcept

Copy constructor (only when copyable is true).

Parameters
otherThe AnyBase to copy from

◆ AnyBase() [4/4]

template<std::size_t sb_size, bool copyable = true>
Acts::AnyBase< sb_size, copyable >::AnyBase ( AnyBase< sb_size, copyable > && other)
noexcept

Move constructor.

Parameters
otherThe AnyBase to move from

Member Function Documentation

◆ as() [1/2]

template<std::size_t sb_size, bool copyable = true>
template<typename T>
T & Acts::AnyBase< sb_size, copyable >::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 sb_size, bool copyable = true>
template<typename T>
const T & Acts::AnyBase< sb_size, copyable >::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

◆ asPtr() [1/2]

template<std::size_t sb_size, bool copyable = true>
template<typename T>
T * Acts::AnyBase< sb_size, copyable >::asPtr ( )

Get pointer to stored value of specified type.

Template Parameters
TType to retrieve (must be exact type, no const/ref)
Returns
Pointer to the stored value, or nullptr if the type doesn't match or the Any is empty

◆ asPtr() [2/2]

template<std::size_t sb_size, bool copyable = true>
template<typename T>
const T * Acts::AnyBase< sb_size, copyable >::asPtr ( ) const

Get const pointer to stored value of specified type.

Template Parameters
TType to retrieve (must be exact type, no const/ref)
Returns
Const pointer to the stored value, or nullptr if the type doesn't match or the Any is empty

◆ emplace()

template<std::size_t sb_size, bool copyable = true>
template<typename T, typename... Args>
requires (isStorable<std::decay_t<T>>())
T & Acts::AnyBase< sb_size, copyable >::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 sb_size, bool copyable = true>
Acts::AnyBase< sb_size, copyable >::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 sb_size, bool copyable = true>
AnyBase & Acts::AnyBase< sb_size, copyable >::operator= ( AnyBase< sb_size, copyable > && other)
noexcept

Move assignment operator.

Parameters
otherThe AnyBase to move from
Returns
Reference to this object

◆ operator=() [2/2]

template<std::size_t sb_size, bool copyable = true>
AnyBase & Acts::AnyBase< sb_size, copyable >::operator= ( const AnyBase< sb_size, copyable > & other)
noexcept

Copy assignment operator (only when copyable is true).

Parameters
otherThe AnyBase to copy from
Returns
Reference to this object

◆ take()

template<std::size_t sb_size, bool copyable = true>
template<typename T>
T Acts::AnyBase< sb_size, copyable >::take ( )

Move the stored value out.

Leaves this Any empty.

Template Parameters
TType to retrieve (must be exact type, no const/ref)
Returns
The moved-out value
Exceptions
std::bad_any_castif stored type doesn't match T or Any is empty

◆ typeInfo()

template<std::size_t sb_size, bool copyable = true>
const std::type_info * Acts::AnyBase< sb_size, copyable >::typeInfo ( ) const

Type info of the stored value.

Returns nullptr if empty.

Returns
Pointer to the type info of the stored value, or nullptr if empty