Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Data Structures | Public Member Functions | Friends
ext::variant< Ts > Class Template Reference

Implementation of the variant class allowing to store any type of those listed in the template parameters. Void type is allowed, multiply specified same type is irrelevant. More...

#include <variant.hpp>

Inheritance diagram for ext::variant< Ts >:
[legend]
Collaboration diagram for ext::variant< Ts >:
[legend]

Public Member Functions

 variant ()=default
 
 variant (const variant &other)=default
 
 variant (variant &&other)=default
 
variantoperator= (variant &&other)=default
 
variantoperator= (const variant &other)=default
 
template<typename T >
bool is () const
 Function to test whether the variant currently contains type T. More...
 
template<typename T >
requires ( ext::Included < std::decay_t < T >, Ts ... > )
void set (T &&value)
 Allows to assign a value to the variant. More...
 
template<typename T >
T & get () &
 Allows to retrieve a value from the variant. More...
 
template<typename T >
const T & get () const &
 Allows to retrieve a value from the variant. More...
 
template<typename T >
T && get () &&
 Allows to retrieve a value from the variant. More...
 
template<class Result , class Callable >
Result call (Callable callable) const
 Callback executor on current variant value. More...
 
template<ext::Included< Ts ... > T>
auto operator<=> (const T &other) const
 
template<ext::Included< Ts ... > T>
bool operator== (const T &other) const
 

Friends

template<class Visitor , class... Variants>
constexpr friend auto visit (Visitor &&vis, Variants &&... vars)
 
ext::ostreamoperator<< (ext::ostream &out, const variant< Ts ... > &obj)
 Operator to print the variant to the output stream. More...
 

Detailed Description

template<typename ... Ts>
class ext::variant< Ts >

Implementation of the variant class allowing to store any type of those listed in the template parameters. Void type is allowed, multiply specified same type is irrelevant.

Template Parameters
Ts... pack of allowed types.

Constructor & Destructor Documentation

◆ variant() [1/3]

template<typename ... Ts>
ext::variant< Ts >::variant ( )
default

Default constructor needed by g++ since it is not inherited

◆ variant() [2/3]

template<typename ... Ts>
ext::variant< Ts >::variant ( const variant< Ts > &  other)
default

Copy constructor needed by g++ since it is not inherited

◆ variant() [3/3]

template<typename ... Ts>
ext::variant< Ts >::variant ( variant< Ts > &&  other)
default

Move constructor needed by g++ since it is not inherited

Member Function Documentation

◆ call()

template<typename ... Ts>
template<class Result , class Callable >
Result ext::variant< Ts >::call ( Callable  callable) const
inline

Callback executor on current variant value.

Template Parameters
Resultthe uniform result type
Callabletype of callable able to accept any variant type.
Parameters
callableobject of callable type able to accept any variant type via function call operator. The possible void type is represented by call with no parameters
Returns
the result of the callable on the current variable type
Here is the call graph for this function:

◆ get() [1/3]

template<typename ... Ts>
template<typename T >
T & ext::variant< Ts >::get ( ) &
inline

Allows to retrieve a value from the variant.

Template Parameters
Tthe type of the value to retrieve
Returns
value retrieved from the variant
Exceptions
bad_castexception if the variant stores different type than specified
Here is the caller graph for this function:

◆ get() [2/3]

template<typename ... Ts>
template<typename T >
T && ext::variant< Ts >::get ( ) &&
inline

Allows to retrieve a value from the variant.

Template Parameters
Tthe type of the value to retrieve
Returns
value retrieved from the variant
Exceptions
bad_castexception if the variant stores different type than specified

◆ get() [3/3]

template<typename ... Ts>
template<typename T >
const T & ext::variant< Ts >::get ( ) const &
inline

Allows to retrieve a value from the variant.

Template Parameters
Tthe type of the value to retrieve
Returns
value retrieved from the variant
Exceptions
bad_castexception if the variant stores different type than specified

◆ is()

template<typename ... Ts>
template<typename T >
bool ext::variant< Ts >::is ( ) const
inline

Function to test whether the variant currently contains type T.

Template Parameters
Tthe type to test
Returns
true it the variant contains instance of type T

◆ operator<=>()

template<typename ... Ts>
template<ext::Included< Ts ... > T>
auto ext::variant< Ts >::operator<=> ( const T &  other) const
inline

◆ operator=() [1/2]

template<typename ... Ts>
variant & ext::variant< Ts >::operator= ( const variant< Ts > &  other)
default

Move operator = needed by g++ since it is not inherited

◆ operator=() [2/2]

template<typename ... Ts>
variant & ext::variant< Ts >::operator= ( variant< Ts > &&  other)
default

Copy operator = needed by g++ since it is not inherited

◆ operator==()

template<typename ... Ts>
template<ext::Included< Ts ... > T>
bool ext::variant< Ts >::operator== ( const T &  other) const
inline

◆ set()

template<typename ... Ts>
template<typename T >
requires ( ext::Included < std::decay_t < T >, Ts ... > )
void ext::variant< Ts >::set ( T &&  value)
inline

Allows to assign a value to the variant.

Template Parameters
Tthe type of the value to assign
Parameters
valuethe new value to assign to the variant

Friends And Related Function Documentation

◆ operator<<

template<typename ... Ts>
ext::ostream & operator<< ( ext::ostream out,
const variant< Ts ... > &  obj 
)
friend

Operator to print the variant to the output stream.

Parameters
outthe output stream
objthe variant to print
Returns
the output stream from the out

◆ visit

template<typename ... Ts>
template<class Visitor , class... Variants>
constexpr friend auto visit ( Visitor &&  vis,
Variants &&...  vars 
)
friend

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