IDS peak ICV v1.6.0
Loading...
Searching...
No Matches
Any Class Reference

#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.
 
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 >
const T & AnyCast () const
 Const version of AnyCast.
 
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]

Any ( )
default

Default constructor. Constructs an empty Any object.

Since
ids_peak_common 1.0

◆ Any() [2/5]

template<typename T >
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 >
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]

Any ( const Any & other)
inline

Copy constructor.

Since
ids_peak_common 1.0

◆ Any() [5/5]

Any ( Any && other)
defaultnoexcept

Move constructor.

Since
ids_peak_common 1.0

Member Function Documentation

◆ AnyCast() [1/2]

template<typename T >
T & 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 >
const T & 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()

const std::type_info & 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()

bool 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 & operator= ( Any && other)
defaultnoexcept

Move assignment operator.

Since
ids_peak_common 1.0

◆ operator=() [2/2]

Any & operator= ( const Any & other)
inline

Copy assignment operator.

Since
ids_peak_common 1.0

◆ Reset()

void Reset ( )
inline

Clears the stored value.

Since
ids_peak_common 1.0