SPH
Classes | Public Member Functions | Friends | List of all members
Any Class Reference

Type-safe object that can store value of any type, similar to std::any. More...

#include <Any.h>

Public Member Functions

 Any ()=default
 Constructs an empty Any. More...
 
 Any (const Any &other)
 Copies the value from another Any. More...
 
 Any (Any &&other)
 Moves the value from another Any. More...
 
template<typename Type , typename = std::enable_if_t<!std::is_same<Any, std::decay_t<Type>>::value>>
 Any (Type &&value)
 Constructs Any from given value, type is deduced. More...
 
Anyoperator= (const Any &other)
 Copies the value from another Any. More...
 
Anyoperator= (Any &&other)
 Moves the value from another Any. More...
 
template<typename Type , typename = std::enable_if_t<!std::is_same<Any, std::decay_t<Type>>::value>>
Anyoperator= (Type &&value)
 Assigns given value to Any, type is deduced. More...
 
template<typename Type >
 operator const Type & () const
 Returns the value from Any. More...
 
template<typename Type >
 operator Type & ()
 Returns the reference to the stored value in Any. More...
 
bool hasValue () const
 Checks if Any currently holds a values. More...
 
template<typename Type , typename = std::enable_if_t<!std::is_same<Any, std::decay_t<Type>>::value>>
bool operator== (Type &&value) const
 Compares Any with another value. More...
 
template<typename Type , typename = std::enable_if_t<!std::is_same<Any, std::decay_t<Type>>::value>>
bool operator!= (Type &&value) const
 

Friends

template<typename Type >
Optional< Type > anyCast (const Any &any)
 Tries to extract value of given type from Any. More...
 

Detailed Description

Type-safe object that can store value of any type, similar to std::any.

Definition at line 15 of file Any.h.

Constructor & Destructor Documentation

◆ Any() [1/4]

Any::Any ( )
default

Constructs an empty Any.

◆ Any() [2/4]

Any::Any ( const Any other)
inline

Copies the value from another Any.

Definition at line 95 of file Any.h.

◆ Any() [3/4]

Any::Any ( Any &&  other)
inline

Moves the value from another Any.

Definition at line 100 of file Any.h.

◆ Any() [4/4]

template<typename Type , typename = std::enable_if_t<!std::is_same<Any, std::decay_t<Type>>::value>>
Any::Any ( Type &&  value)
inline

Constructs Any from given value, type is deduced.

Definition at line 106 of file Any.h.

Member Function Documentation

◆ hasValue()

bool Any::hasValue ( ) const
inline

Checks if Any currently holds a values.

Definition at line 152 of file Any.h.

◆ operator const Type &()

template<typename Type >
Any::operator const Type & ( ) const
inlineexplicit

Returns the value from Any.

If Any does not store any value or the value has different type, the result is undefined. In debug build, it is checked by assert.

Definition at line 138 of file Any.h.

◆ operator Type &()

template<typename Type >
Any::operator Type & ( )
inlineexplicit

Returns the reference to the stored value in Any.

If Any does not store any value or the value has different type, the result is undefined. In debug build, it is checked by assert.

Definition at line 147 of file Any.h.

◆ operator!=()

template<typename Type , typename = std::enable_if_t<!std::is_same<Any, std::decay_t<Type>>::value>>
bool Any::operator!= ( Type &&  value) const
inline

Definition at line 172 of file Any.h.

◆ operator=() [1/3]

Any& Any::operator= ( Any &&  other)
inline

Moves the value from another Any.

Definition at line 121 of file Any.h.

◆ operator=() [2/3]

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

Copies the value from another Any.

Definition at line 111 of file Any.h.

◆ operator=() [3/3]

template<typename Type , typename = std::enable_if_t<!std::is_same<Any, std::decay_t<Type>>::value>>
Any& Any::operator= ( Type &&  value)
inline

Assigns given value to Any, type is deduced.

Definition at line 128 of file Any.h.

◆ operator==()

template<typename Type , typename = std::enable_if_t<!std::is_same<Any, std::decay_t<Type>>::value>>
bool Any::operator== ( Type &&  value) const
inline

Compares Any with another value.

Returns true if and only if both types and values are equal.

Definition at line 166 of file Any.h.

Friends And Related Function Documentation

◆ anyCast

template<typename Type >
Optional<Type> anyCast ( const Any any)
friend

Tries to extract value of given type from Any.

On success returns the value, otherwise NOTHING.

Definition at line 178 of file Any.h.


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