ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
Acts::AnyBase< SbSize, Copyable, Base > Class Template Reference

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

#include <Acts/Utilities/Any.hpp>

Inheritance diagram for Acts::AnyBase< SbSize, Copyable, Base >:
[legend]
Collaboration diagram for Acts::AnyBase< SbSize, Copyable, Base >:
[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)
 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 (!std::is_base_of_v<AnyBaseAll, std::decay_t<T>> && isStorable<std::decay_t<T>>())
 AnyBase (T &&value)
 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 B = Base>
requires (!std::is_void_v<B>)
B * asBase ()
 Get a pointer to the stored value as Base*, regardless of its concrete type.
template<typename B = Base>
requires (!std::is_void_v<B>)
const B * asBase () const
 Get a const pointer to the stored value as Base*.
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.
template<typename B = Base>
requires (!std::is_void_v<B>)
B & operator* ()
 Dereference to the stored value as Base&.
template<typename B = Base>
requires (!std::is_void_v<B>)
const B & operator* () const
 Dereference to the stored value as const Base&.
template<typename B = Base>
requires (!std::is_void_v<B>)
B * operator-> ()
 Member access on the stored value as Base*.
template<typename B = Base>
requires (!std::is_void_v<B>)
const B * operator-> () const
 Member access on the stored value as const Base*.
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)
 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 SbSize, bool Copyable = true, typename Base = void>
class Acts::AnyBase< SbSize, Copyable, Base >

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

Template Parameters
SbSizeSize 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) <= SbSize) 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) > SbSize) 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 SbSize, bool Copyable = true, typename Base = void>
template<typename T, typename... Args>
requires (isStorable<std::decay_t<T>>())
Acts::AnyBase< SbSize, Copyable, Base >::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 SbSize, bool Copyable = true, typename Base = void>
template<typename T>
requires (!std::is_base_of_v<AnyBaseAll, std::decay_t<T>> && isStorable<std::decay_t<T>>())
Acts::AnyBase< SbSize, Copyable, Base >::AnyBase ( T && value)
explicit

Construct from any value type.

Template Parameters
TType of the value to store
Parameters
valueValue to store in the Any
Note
Not noexcept: storing a type larger than the small buffer allocates on the heap (may throw std::bad_alloc) and the stored type's own constructor may throw.

◆ AnyBase() [3/4]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
Acts::AnyBase< SbSize, Copyable, Base >::AnyBase ( const AnyBase< SbSize, Copyable, Base > & other)

Copy constructor (only when Copyable is true).

Parameters
otherThe AnyBase to copy from
Note
Not noexcept: copying a heap-allocated value allocates (may throw std::bad_alloc) and the stored type's copy constructor may throw.

◆ AnyBase() [4/4]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
Acts::AnyBase< SbSize, Copyable, Base >::AnyBase ( AnyBase< SbSize, Copyable, Base > && other)
noexcept

Move constructor.

Parameters
otherThe AnyBase to move from

Member Function Documentation

◆ as() [1/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
template<typename T>
T & Acts::AnyBase< SbSize, Copyable, Base >::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 SbSize, bool Copyable = true, typename Base = void>
template<typename T>
const T & Acts::AnyBase< SbSize, Copyable, Base >::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

◆ asBase() [1/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
template<typename B = Base>
requires (!std::is_void_v<B>)
B * Acts::AnyBase< SbSize, Copyable, Base >::asBase ( )

Get a pointer to the stored value as Base*, regardless of its concrete type.

Only available when Base is not void.

Returns
Pointer to the stored value upcast to Base*, or nullptr if empty

◆ asBase() [2/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
template<typename B = Base>
requires (!std::is_void_v<B>)
const B * Acts::AnyBase< SbSize, Copyable, Base >::asBase ( ) const

Get a const pointer to the stored value as Base*.

Only available when Base is not void.

Returns
Const pointer to the stored value upcast to Base*, or nullptr if empty

◆ asPtr() [1/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
template<typename T>
T * Acts::AnyBase< SbSize, Copyable, Base >::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 SbSize, bool Copyable = true, typename Base = void>
template<typename T>
const T * Acts::AnyBase< SbSize, Copyable, Base >::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 SbSize, bool Copyable = true, typename Base = void>
template<typename T, typename... Args>
requires (isStorable<std::decay_t<T>>())
T & Acts::AnyBase< SbSize, Copyable, Base >::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 SbSize, bool Copyable = true, typename Base = void>
Acts::AnyBase< SbSize, Copyable, Base >::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 SbSize, bool Copyable = true, typename Base = void>
template<typename B = Base>
requires (!std::is_void_v<B>)
B & Acts::AnyBase< SbSize, Copyable, Base >::operator* ( )

Dereference to the stored value as Base&.

Only available when Base is not void.

Returns
Reference to the stored value upcast to Base&

◆ operator*() [2/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
template<typename B = Base>
requires (!std::is_void_v<B>)
const B & Acts::AnyBase< SbSize, Copyable, Base >::operator* ( ) const

Dereference to the stored value as const Base&.

Only available when Base is not void.

Returns
Const reference to the stored value upcast to Base&

◆ operator->() [1/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
template<typename B = Base>
requires (!std::is_void_v<B>)
B * Acts::AnyBase< SbSize, Copyable, Base >::operator-> ( )

Member access on the stored value as Base*.

Only available when Base is not void.

Returns
Pointer to the stored value upcast to Base*

◆ operator->() [2/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
template<typename B = Base>
requires (!std::is_void_v<B>)
const B * Acts::AnyBase< SbSize, Copyable, Base >::operator-> ( ) const

Member access on the stored value as const Base*.

Only available when Base is not void.

Returns
Const pointer to the stored value upcast to Base*

◆ operator=() [1/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
AnyBase & Acts::AnyBase< SbSize, Copyable, Base >::operator= ( AnyBase< SbSize, Copyable, Base > && other)
noexcept

Move assignment operator.

Parameters
otherThe AnyBase to move from
Returns
Reference to this object

◆ operator=() [2/2]

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
AnyBase & Acts::AnyBase< SbSize, Copyable, Base >::operator= ( const AnyBase< SbSize, Copyable, Base > & other)

Copy assignment operator (only when Copyable is true).

Parameters
otherThe AnyBase to copy from
Returns
Reference to this object
Note
Not noexcept: copying a heap-allocated value allocates (may throw std::bad_alloc) and the stored type's copy operations may throw.

◆ take()

template<std::size_t SbSize, bool Copyable = true, typename Base = void>
template<typename T>
T Acts::AnyBase< SbSize, Copyable, Base >::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 SbSize, bool Copyable = true, typename Base = void>
const std::type_info * Acts::AnyBase< SbSize, Copyable, Base >::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