Loading...
Searching...
No Matches
variant

## Classes

class | etl::variant_exception
class | etl::variant_incorrect_type_exception
class | etl::bad_variant_access
class | etl::variant_not_a_base_exception
class | etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >

## Typedefs

typedef etl::monostate | etl::monostate

## Detailed Description

A class that can contain one a several specified types in a type safe manner.

## Class Documentation

## etl::variant_exception

class etl::variant_exception

Base exception for the variant class.

### Public Member Functions

| variant_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::exception
ETL_EXCEPTION_CONSTEXPR | exception (string_type reason_, string_type, numeric_type)
| Constructor.
ETL_EXCEPTION_CONSTEXPR string_type | what () const ETL_NOEXCEPT ETL_EXCEPTION_OVERRIDE
ETL_EXCEPTION_CONSTEXPR string_type | file_name () const
ETL_EXCEPTION_CONSTEXPR numeric_type | line_number () const

## Additional Inherited Members

Public Types inherited from etl::exception
typedef const char * | string_type
typedef int | numeric_type

## etl::variant_incorrect_type_exception

class etl::variant_incorrect_type_exception

'Unsupported type' exception for the variant class.

### Public Member Functions

| variant_incorrect_type_exception (string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::variant_exception
| variant_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::exception
ETL_EXCEPTION_CONSTEXPR | exception (string_type reason_, string_type, numeric_type)
| Constructor.
ETL_EXCEPTION_CONSTEXPR string_type | what () const ETL_NOEXCEPT ETL_EXCEPTION_OVERRIDE
ETL_EXCEPTION_CONSTEXPR string_type | file_name () const
ETL_EXCEPTION_CONSTEXPR numeric_type | line_number () const

## Additional Inherited Members

Public Types inherited from etl::exception
typedef const char * | string_type
typedef int | numeric_type

## etl::bad_variant_access

class etl::bad_variant_access

'Bad variant access' exception for the variant class.

### Public Member Functions

| bad_variant_access (string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::variant_exception
| variant_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::exception
ETL_EXCEPTION_CONSTEXPR | exception (string_type reason_, string_type, numeric_type)
| Constructor.
ETL_EXCEPTION_CONSTEXPR string_type | what () const ETL_NOEXCEPT ETL_EXCEPTION_OVERRIDE
ETL_EXCEPTION_CONSTEXPR string_type | file_name () const
ETL_EXCEPTION_CONSTEXPR numeric_type | line_number () const

## Additional Inherited Members

Public Types inherited from etl::exception
typedef const char * | string_type
typedef int | numeric_type

## etl::variant_not_a_base_exception

class etl::variant_not_a_base_exception

'Not a base type' exception for the variant class.

### Public Member Functions

| variant_not_a_base_exception (string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::variant_exception
| variant_exception (string_type reason_, string_type file_name_, numeric_type line_number_)
Public Member Functions inherited from etl::exception
ETL_EXCEPTION_CONSTEXPR | exception (string_type reason_, string_type, numeric_type)
| Constructor.
ETL_EXCEPTION_CONSTEXPR string_type | what () const ETL_NOEXCEPT ETL_EXCEPTION_OVERRIDE
ETL_EXCEPTION_CONSTEXPR string_type | file_name () const
ETL_EXCEPTION_CONSTEXPR numeric_type | line_number () const

## Additional Inherited Members

Public Types inherited from etl::exception
typedef const char * | string_type
typedef int | numeric_type

## etl::variant

class etl::variant

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
class etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >

A template class that can store any of the types defined in the template parameter list. Supports up to 8 types.

### Public Types

typedef uint_least8_t | type_id_t
| The type used for ids.
typedef reader_type< T1, T2, T3, T4, T5, T6, T7, T8 > | reader
| The base type for derived readers.

### Public Member Functions

| ~variant ()
| Destructor.
template<typename T>
| variant (const T &value)
template<size_t Index, typename T>
| variant (etl::in_place_index_t< Index >, T const &value)
| variant (const variant &other)
template<typename T>
T & | emplace ()
| Emplace with one constructor parameter.
template<typename T, typename TP1>
T & | emplace (const TP1 &value1)
| Emplace with one constructor parameter.
template<typename T, typename TP1, typename TP2>
T & | emplace (const TP1 &value1, const TP2 &value2)
| Emplace with two constructor parameters.
template<typename T, typename TP1, typename TP2, typename TP3>
T & | emplace (const TP1 &value1, const TP2 &value2, const TP3 &value3)
| Emplace with three constructor parameters.
template<typename T, typename TP1, typename TP2, typename TP3, typename TP4>
T & | emplace (const TP1 &value1, const TP2 &value2, const TP3 &value3, const TP4 &value4)
| Emplace with four constructor parameters.
template<typename T>
variant & | operator= (const T &value)
variant & | operator= (const variant &other)
bool | is_same_type (const variant &other) const
template<typename V1, typename V2, typename V3, typename V4, typename V5, typename V6, typename V7, typename V8>
bool | is_same_type (const variant< V1, V2, V3, V4, V5, V6, V7, V8 > &other) const
void | call (reader &r)
bool | is_valid () const
template<typename T>
bool | is_type () const
size_t | index () const
| Gets the index of the type currently stored or UNSUPPORTED_TYPE_ID.
void | clear ()
| Clears the value to 'no valid stored value'.
template<typename T>
T & | get ()
template<typename T>
const T & | get () const
template<typename TBase>
TBase * | upcast_ptr ()
template<typename TBase>
TBase & | upcast ()
template<typename TBase>
const TBase * | upcast_ptr () const
template<typename TBase>
const TBase & | upcast () const
template<typename TBase>
bool | is_base_of () const
| Check that TBase is a base class of the current variant value.
| operator T1 & ()
| Conversion operators for each type.
| operator T2 & ()
| operator T3 & ()
| operator T4 & ()
| operator T5 & ()
| operator T6 & ()
| operator T7 & ()
| operator T8 & ()

### Static Public Member Functions

template<typename T>
static bool | is_supported_type ()

### Static Public Attributes

static const type_id_t | UNSUPPORTED_TYPE_ID = etl::integral_limits<type_id_t>::max
| The id a unsupported types.

#### Constructor & Destructor Documentation

## variant() [1/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename T>

etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::variant | ( | const T & | value | ) |

inline

Constructor that catches any types that are not supported. Forces a ETL_STATIC_ASSERT.

## variant() [2/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<size_t Index, typename T>

etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::variant | ( | etl::in_place_index_t< Index > | ,
|  | T const & | value )

inline explicit

Constructor that catches any types that are not supported. Forces a ETL_STATIC_ASSERT.

#### Member Function Documentation

## call()

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>

void etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::call | ( | reader & | r | ) |

inline

Calls the supplied reader instance. The 'read' function appropriate to the current type is called with the stored value.

## get() [1/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename T>

T & etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::get | ( |  | ) |

inline

Gets the value stored as the specified template type. Throws a variant_incorrect_type_exception if the actual type is not that specified.

Returns
  A reference to the value.

## get() [2/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename T>

const T & etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::get | ( |  | ) | const

inline

Gets the value stored as the specified template type. Throws a variant_incorrect_type_exception if the actual type is not that specified.

Returns
  A const reference to the value.

## is_same_type() [1/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>

bool etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::is_same_type | ( | const variant< T1, T2, T3, T4, T5, T6, T7, T8 > & | other | ) | const

inline

Checks if the type is the same as the current stored type. For variants with the same type declarations.

Returns
  true if the types are the same, otherwise false.

## is_same_type() [2/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename V1, typename V2, typename V3, typename V4, typename V5, typename V6, typename V7, typename V8>

bool etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::is_same_type | ( | const variant< V1, V2, V3, V4, V5, V6, V7, V8 > & | other | ) | const

inline

Checks if the type is the same as the current stored type. For variants with differing declarations.

Returns
  true if the types are the same, otherwise false.

## is_supported_type()

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename T>

bool etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::is_supported_type | ( |  | ) |

inline static

Checks if the template type is supported by the implementation of variant..

Returns
  true if the type is supported, otherwise false.

## is_type()

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename T>

bool etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::is_type | ( |  | ) | const

inline

Checks to see if the type currently stored is the same as that specified in the template parameter.

Returns
  true if it is the specified type, otherwise b>false.

## is_valid()

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>

bool etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::is_valid | ( |  | ) | const

inline

Checks whether a valid value is currently stored.

Returns
  true if the value is valid, otherwise false.

## operator=() [1/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename T>

variant & etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::operator= | ( | const T & | value | ) |

inline

Assignment operator for T1 type.

Parameters

  value | The value to assign.

## operator=() [2/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>

variant & etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::operator= | ( | const variant< T1, T2, T3, T4, T5, T6, T7, T8 > & | other | ) |

inline

Assignment operator for variant type.

Parameters

  other | The variant to assign.

## upcast() [1/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename TBase>

TBase & etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::upcast | ( |  | ) |

inline

Gets the value stored as the specified template type.

Returns
  A reference to the value.

## upcast() [2/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename TBase>

const TBase & etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::upcast | ( |  | ) | const

inline

Gets the value stored as the specified template type.

Returns
  A const reference to the value.

## upcast_ptr() [1/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename TBase>

TBase * etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::upcast_ptr | ( |  | ) |

inline

Gets the value stored as the specified template type.

Returns
  A pointer to the value.

## upcast_ptr() [2/2]

template<typename T1, typename T2 = etl::null_type<2>, typename T3 = etl::null_type<3>, typename T4 = etl::null_type<4>, typename T5 = etl::null_type<5>, typename T6 = etl::null_type<6>, typename T7 = etl::null_type<7>, typename T8 = etl::null_type<8>>
template<typename TBase>

const TBase * etl::variant< T1, T2, T3, T4, T5, T6, T7, T8 >::upcast_ptr | ( |  | ) | const

inline

Gets the value stored as the specified template type.

Returns
  A const pointer to the value.

## Typedef Documentation

## monostate

typedef etl::monostate etl::monostate

Monostate for variants.