Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
Public Member Functions | Public Attributes | Friends | List of all members
serac::variant< T0, T1 > Struct Template Reference

A simple variant type that supports only two elements. More...

#include <variant.hpp>

Public Member Functions

constexpr variant ()=default
 Default constructor - will default-initialize first member of the variant.
 
constexpr variant (const variant &)=default
 Default constructor. More...
 
constexpr variant (variant &&)=default
 Default constructor.
 
template<typename T , typename SFINAE = std::enable_if_t<detail::is_variant_assignable<T, T0, T1>::value>>
constexpr variant (T &&t)
 "Parameterized" constructor with which a value can be assigned More...
 
constexpr variantoperator= (const variant &)=default
 Default assignment operator. More...
 
constexpr variantoperator= (variant &&)=default
 Default assignment operator. More...
 
template<typename T , typename SFINAE = std::enable_if_t<detail::is_variant_assignable<T, T0, T1>::value>>
constexpr variantoperator= (T &&t)
 
constexpr int index () const
 Returns the index of the active variant member.
 

Public Attributes

detail::variant_storage< T0, T1 > storage_
 Storage abstraction used to provide constexpr functionality when applicable.
 

Friends

template<int I>
constexpr friend variant_alternative< I, T0, T1 >::typeget (variant &v)
 Returns the variant member at the provided index. More...
 
template<int I>
constexpr friend const variant_alternative< I, T0, T1 >::typeget (const variant &v)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 

Detailed Description

template<typename T0, typename T1>
struct serac::variant< T0, T1 >

A simple variant type that supports only two elements.

Avoids the recursive template instantiation associated with std::variant and provides a (roughly) identical interface that is fully constexpr (when both types are trivially destructible)

Template Parameters
T0The first member type of the variant
T1The second member type of the variant

Definition at line 207 of file variant.hpp.

Constructor & Destructor Documentation

◆ variant() [1/2]

template<typename T0 , typename T1 >
constexpr serac::variant< T0, T1 >::variant ( const variant< T0, T1 > &  )
constexprdefault

Default constructor.

Note
These are needed explicitly so the variant(T&&) doesn't match first

◆ variant() [2/2]

template<typename T0 , typename T1 >
template<typename T , typename SFINAE = std::enable_if_t<detail::is_variant_assignable<T, T0, T1>::value>>
constexpr serac::variant< T0, T1 >::variant ( T &&  t)
inlineconstexpr

"Parameterized" constructor with which a value can be assigned

Template Parameters
TThe type of the parameter to assign to one of the variant elements
Parameters
[in]tThe parameter to assign to the variant's contents
Precondition
The parameter type T must be equal to or assignable to either T0 or T1
Note
If the conversion is ambiguous, i.e., if t is equal or convertible to both T0 and T1, the first element of the variant - of type T0 - will be assigned to

Definition at line 238 of file variant.hpp.

Member Function Documentation

◆ operator=() [1/3]

template<typename T0 , typename T1 >
constexpr variant& serac::variant< T0, T1 >::operator= ( const variant< T0, T1 > &  )
constexprdefault

Default assignment operator.

Note
These are needed explicitly so the operator=(T&&) doesn't match first
Returns
The modified variant

◆ operator=() [2/3]

template<typename T0 , typename T1 >
template<typename T , typename SFINAE = std::enable_if_t<detail::is_variant_assignable<T, T0, T1>::value>>
constexpr variant& serac::variant< T0, T1 >::operator= ( T &&  t)
inlineconstexpr

"Parameterized" assignment with which a value can be assigned

Template Parameters
TThe type of the parameter to assign to one of the variant elements
Parameters
[in]tThe parameter to assign to the variant's contents
See also
variant::variant(T&& t) for notes and preconditions

Definition at line 273 of file variant.hpp.

◆ operator=() [3/3]

template<typename T0 , typename T1 >
constexpr variant& serac::variant< T0, T1 >::operator= ( variant< T0, T1 > &&  )
constexprdefault

Default assignment operator.

Returns
The modified variant

Friends And Related Function Documentation

◆ get

template<typename T0 , typename T1 >
template<int I>
constexpr friend variant_alternative<I, T0, T1>::type& get ( variant< T0, T1 > &  v)
friend

Returns the variant member at the provided index.

Template Parameters
IThe index of the element to retrieve
See also
std::variant::get
Template Parameters
TThe type of the element to retrieve
T0The first member type of the variant
T1The second member type of the variant
Parameters
[in]vThe variant to return the element of
See also
std::variant::get
Precondition
T must be either T0 or T1
Note
If T == T0 == T1, the element at index 0 will be returned

Definition at line 304 of file variant.hpp.


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