openPMD-api
 
Loading...
Searching...
No Matches
openPMD::auxiliary::Variant< T_DTYPES, variant_types > Class Template Reference

Generic object to store a set of datatypes in without losing type safety. More...

#include <Variant.hpp>

Classes

struct  from_any_tag
 
struct  from_basic_type_tag
 

Public Member Functions

template<typename U>
 Variant (from_basic_type_tag, U)
 
 Variant (from_any_tag, std::any)
 
template<typename U>
 Variant (U u)
 Construct a lightweight wrapper around a generic object that indicates the concrete datatype of the specific object stored.
 
template<typename U>
U const & get () const
 Retrieve a stored specific object of known datatype with ensured type-safety.
 
template<typename variant_t>
variant_t const & getVariant () const
 Retrieve the stored generic object.
 
std::any const & getAny () const
 
size_t index () const
 Retrieve the index of the alternative that is currently been held.
 
template<typename U>
U const & get () const
 

Public Attributes

T_DTYPES dtype
 

Static Public Attributes

static constexpr from_basic_type_tag from_basic_type
 
static constexpr from_any_tag from_any = from_any_tag{}
 

Detailed Description

template<class T_DTYPES, typename... variant_types>
class openPMD::auxiliary::Variant< T_DTYPES, variant_types >

Generic object to store a set of datatypes in without losing type safety.

Template Parameters
T_DTYPESEnumeration of datatypes to be stored and identified.
TVaraidic template argument list of datatypes to be stored.

Constructor & Destructor Documentation

◆ Variant()

template<typename T_DTYPES, typename... variant_types>
template<typename U>
openPMD::auxiliary::Variant< T_DTYPES, variant_types >::Variant ( U u)

Construct a lightweight wrapper around a generic object that indicates the concrete datatype of the specific object stored.

Note
Gerneric objects can only generated implicitly if their datatype is contained in T_DTYPES.
Parameters
uGeneric object to be stored.

Member Function Documentation

◆ get()

template<class T_DTYPES, typename... variant_types>
template<typename U>
U const & openPMD::auxiliary::Variant< T_DTYPES, variant_types >::get ( ) const
nodiscard

Retrieve a stored specific object of known datatype with ensured type-safety.

Exceptions
std::bad_variant_accessif stored object is not of type U.
Template Parameters
UType of the object to be retrieved.
Returns
Copy of the retrieved object of type U.

◆ getVariant()

template<class T_DTYPES, typename... variant_types>
template<typename variant_t>
variant_t const & openPMD::auxiliary::Variant< T_DTYPES, variant_types >::getVariant ( ) const
inlinenodiscard

Retrieve the stored generic object.

Returns
Copy of the stored generic object.

◆ index()

template<typename T_DTYPES, typename... variant_types>
size_t openPMD::auxiliary::Variant< T_DTYPES, variant_types >::index ( ) const
nodiscard

Retrieve the index of the alternative that is currently been held.

Returns
zero-based index

Member Data Documentation

◆ from_basic_type

template<class T_DTYPES, typename... variant_types>
from_basic_type_tag openPMD::auxiliary::Variant< T_DTYPES, variant_types >::from_basic_type
staticconstexpr
Initial value:

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