IDS peak ICV v1.0.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

Definition at line 35 of file peak_common_any.hpp.

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

Definition at line 88 of file peak_common_any.hpp.

◆ 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

Definition at line 101 of file peak_common_any.hpp.

◆ Any() [4/5]

Any ( const Any & other)
inline

Copy constructor.

Since
ids_peak_common 1.0

Definition at line 115 of file peak_common_any.hpp.

◆ 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

Definition at line 179 of file peak_common_any.hpp.

◆ 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

Definition at line 201 of file peak_common_any.hpp.

◆ 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

Definition at line 164 of file peak_common_any.hpp.

◆ 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

Definition at line 220 of file peak_common_any.hpp.

◆ 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

Definition at line 131 of file peak_common_any.hpp.

◆ Reset()

void Reset ( )
inline

Clears the stored value.

Since
ids_peak_common 1.0

Definition at line 152 of file peak_common_any.hpp.