IDS peak genericC++ v1.13.0
Loading...
Searching...
No Matches
peak::common::Any Class Reference

A type-erased container for any copyable value. More...

#include <peak_common/types/peak_common_any.hpp>

Public Member Functions

 Any ()=default
 Default constructor. Constructs an empty Any object.
template<typename T>
 Any (const T &value)
 Constructs an Any from a const reference.
template<typename T>
 Any (T &&value)
 Constructs an Any from a rvalue reference.
 Any (const Any &other)
 Copy constructor.
 Any (Any &&other) noexcept=default
 Move constructor.
Any & operator= (const Any &other)
 Copy assignment operator.
Any & operator= (Any &&other) noexcept=default
 Move assignment operator.
void Reset ()
 Clears the stored value.
PEAK_COMMON_NO_DISCARD const std::type_info & GetType () const
 Gets the type of the stored value.
template<typename T>
T & AnyCast ()
 Casts the stored value to the specified type.
template<typename T>
PEAK_COMMON_NO_DISCARD const T & AnyCast () const
 Const version of AnyCast.
PEAK_COMMON_NO_DISCARD bool HasValue () const
 Checks if the Any contains a value.

Detailed Description

A type-erased container for any copyable value.

This class provides a way to store and retrieve a value of arbitrary type using type erasure. It behaves similarly to std::any and allows type-safe casting via the AnyCast<T>() method.

Since
ids_peak_common 1.0

Constructor & Destructor Documentation

◆ Any() [1/5]

peak::common::Any::Any ( )
default

Default constructor. Constructs an empty Any object.

Since
ids_peak_common 1.0

◆ Any() [2/5]

template<typename T>
peak::common::Any::Any ( const T & value)
inlineexplicit

Constructs an Any from a const reference.

Template Parameters
TThe type of the value to store.
Parameters
valueThe value to store.
Since
ids_peak_common 1.0

◆ Any() [3/5]

template<typename T>
peak::common::Any::Any ( T && value)
inlineexplicit

Constructs an Any from a rvalue reference.

Template Parameters
TThe type of the value to store.
Parameters
valueThe value to store.
Since
ids_peak_common 1.0

◆ Any() [4/5]

peak::common::Any::Any ( const Any & other)
inline

Copy constructor.

Since
ids_peak_common 1.0

◆ Any() [5/5]

peak::common::Any::Any ( Any && other)
defaultnoexcept

Move constructor.

Since
ids_peak_common 1.0

Member Function Documentation

◆ AnyCast() [1/2]

template<typename T>
T & peak::common::Any::AnyCast ( )
inline

Casts the stored value to the specified type.

Template Parameters
TThe expected type of the stored value.
Returns
Reference to the value.
Exceptions
InvalidCastExceptionif the types do not match.
Since
ids_peak_common 1.0

◆ AnyCast() [2/2]

template<typename T>
PEAK_COMMON_NO_DISCARD const T & peak::common::Any::AnyCast ( ) const
inline

Const version of AnyCast.

Template Parameters
TThe expected type of the stored value.
Returns
Const reference to the value.
Exceptions
InvalidCastExceptionif the types do not match.
Since
ids_peak_common 1.0

◆ GetType()

PEAK_COMMON_NO_DISCARD const std::type_info & peak::common::Any::GetType ( ) const
inline

Gets the type of the stored value.

Returns
Type info of the stored value, or typeid(void) if empty.
Since
ids_peak_common 1.0

◆ HasValue()

PEAK_COMMON_NO_DISCARD bool peak::common::Any::HasValue ( ) const
inline

Checks if the Any contains a value.

Returns
True if a value is stored, false otherwise.
Since
ids_peak_common 1.0

◆ operator=() [1/2]

Any & peak::common::Any::operator= ( Any && other)
defaultnoexcept

Move assignment operator.

Since
ids_peak_common 1.0

◆ operator=() [2/2]

Any & peak::common::Any::operator= ( const Any & other)
inline

Copy assignment operator.

Since
ids_peak_common 1.0

◆ Reset()

void peak::common::Any::Reset ( )
inline

Clears the stored value.

Since
ids_peak_common 1.0

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