SPH
Classes | Namespaces | Functions
Variant.h File Reference

Object capable of storing values of different types. More...

#include "common/Assert.h"
#include "common/Globals.h"
#include "math/MathUtils.h"
#include "objects/wrappers/Optional.h"

Go to the source code of this file.

Classes

class  AlignedUnion< TArgs >
 Stores value of type std::aligned_union, having size and alignment equal to maximum of sizes and alignments of template types. More...
 
struct  VariantHelpers::DefaultCreate< TArgs >
 Creates a variant using default constructor. More...
 
struct  VariantHelpers::Delete< TArgs >
 Destroys the object currently stored in variant. More...
 
struct  VariantHelpers::CopyMoveCreate< TArgs >
 Creates a variant by copying/moving value currently stored in other variant. More...
 
struct  VariantHelpers::Assign< TArgs >
 Assigns a value type of which can be stored in variant. More...
 
struct  VariantHelpers::CopyMoveAssign< TArgs >
 Creates a variant by copying/moving value currently stored in other variant. More...
 
struct  VariantHelpers::Swap< TArgs >
 Swaps content of two variants. More...
 
struct  VariantIterator< T0, TArgs >
 Iterates through types of variant until idx-th type is found, and executes given TVisitor, passing arguments to its method visit. More...
 
struct  VariantIterator< T0 >
 Specialization for last type. More...
 
struct  ConstructTypeIdxTag
 Tag for invoking constructor with type index as parameter.
 
class  Variant< TArgs >
 Variant, an implementation of type-safe union, similar to std::variant or boost::variant. More...
 
struct  Detail::ForValue< N, T0, TArgs >
 
struct  Detail::ForValue< N, NothingType, TArgs... >
 
struct  Detail::ForValue< N, T0 >
 

Namespaces

 VariantHelpers
 Helper visitors creating, deleting or modifying Variant.
 
 Detail
 
 std
 Overload of std::swap for Sph::Array.
 

Functions

template<typename TFunctor , typename... TArgs>
decltype(auto) INLINE forValue (Variant< TArgs... > &variant, TFunctor &&functor)
 
template<typename TFunctor , typename... TArgs>
decltype(auto) INLINE forValue (const Variant< TArgs... > &variant, TFunctor &&functor)
 
template<typename... TArgs>
void std::swap (Sph::Variant< TArgs... > &v1, Sph::Variant< TArgs... > &v2)
 

Detailed Description

Object capable of storing values of different types.

Author
Pavel Sevecek (sevecek at sirrah.troja.mff.cuni.cz)
Date
2016-2021

Definition in file Variant.h.

Function Documentation

◆ forValue() [1/2]

template<typename TFunctor , typename... TArgs>
decltype(auto) INLINE forValue ( const Variant< TArgs... > &  variant,
TFunctor &&  functor 
)

Executes a functor passing current value stored in variant as its parameter. Overload for const l-value reference.

Definition at line 435 of file Variant.h.

◆ forValue() [2/2]

template<typename TFunctor , typename... TArgs>
decltype(auto) INLINE forValue ( Variant< TArgs... > &  variant,
TFunctor &&  functor 
)

Executes a functor passing current value stored in variant as its parameter. The functor must either have templated operator() (i.e. generic lambda), or have an overloaded operator for each type contained in variant. If the variant contains type NothingType, the functor not called for this type. This allows to call generic functions, defined on other types while keeping NothingType as a special value representing an empty variant.

Parameters
variantVariant, must contain a value (checked by assert).
functorExecuted functor, takes one parameter - value obtained from Variant.
Returns
Value returned by the functor.

Definition at line 428 of file Variant.h.