ara::core::Variant
A type-safe union that behaves like std::variant from C++17.
ara::core::Variant<int, float> v, w;
v = 42; // v contains int
int i = ara::core::get<int>(v);
w = ara::core::get<int>(v);
w = ara::core::get<0>(v); // same effect as the previous line
w = v; // same effect as the previous line
- Parameters
Ts
the types that the Variant is able to hold
class ara::core::Variant
This class defines a type safe union. The definition of this class is based on C++17 std::variant. Wherever needed, please refer to C++17 standard for more information.
Members
public template<>
inline constexpr
Variant
()
Default constructor. Constructs a variant holding the value-initialized value of the first alternative.
public
Variant
(const
Variant
& other) = default
Copy constructor.
- Parameters
other
other Variant from which to construct.
public
Variant
(
Variant
&& other) = default
Move constructor.
- Parameters
other
other Variant from which to construct.
public template<>
inline constexpr
Variant
(Arg && arg)
Constructs a variant with the specified alternative T and initializes the contained value with the arguments std::forward<Args>(args)
...
-
Parameters
Arg
type of arguments
-
Parameters
arg
arguments to initialize the contained value with
public template<>
inline constexpr explicit
Variant
(
in_place_index_t
< I >, Args &&... args)
Constructs a variant with the alternative T_i specified by the index I and initializes the contained value with the arguments std::forward<Args>(args)
....
-
Parameters
I
indexArgs
type of argument
-
Parameters
args
arguments to initialize the contained value with
public template<>
inline constexpr explicit
Variant
(
in_place_index_t
< I >, std::initializer_list< Up > il, Args &&... args)
Constructs a variant with the alternative T_i specified by the index I and initializes the contained value with the arguments std::forward<Args>(args)
....
-
Parameters
I
indexArgs
type of argument
-
Parameters
args
arguments to initialize the contained value with
public template<>
inline constexpr explicit
Variant
(
in_place_type_t
< T >, Args &&... args)
Constructs a variant with the specified alternative T and initializes the contained value with the arguments std::forward<Args>(args)
....
- Parameters
T
alternative typeArgs
type of arguments
public template<>
inline constexpr explicit
Variant
(
in_place_type_t
< T >, std::initializer_list< Up > il, Args &&... args)
Constructs a variant with the specified alternative T and initializes the contained value with the arguments il, std::forward<Args>(args)
....
- Parameters
T
type of alternativeUp
type of ilArgs
type of arguments
public
~Variant
() = default
Destroy the Variant object.
public
Variant
&
operator=
(const
Variant
&) = default
Assigns a new value to an existing variant object. Please refer to the C++17 std::variant documentation for more details.
- Returns Variant& this variant
public
Variant
&
operator=
(
Variant
&&) = default
Move assigns a new value to an existing variant object. Please refer to the C++17 std::variant documentation for more details.
- Returns Variant& this variant
public template<>
inline
Variant
&
operator=
(Arg && arg)
In place assignment.
-
Parameters
Arg
Type of arguments
-
Parameters
arg
arguments
-
Returns Variant& this variant
public template<>
inline T &
emplace
(Args &&... args)
public template<>
inline T &
emplace
(std::initializer_list< Up > il, Args &&... args)
public inline constexpr bool
valueless_by_exception
() const noexcept
Returns false if and only if the variant holds a value.
-
Returns true variant doesn't hold a value
-
Returns false if and only if the variant holds a value
public inline constexpr std::size_t
index
() const noexcept
Returns the zero-based index of the alternative that is currently held by the variant.
- Returns constexpr std::size_t zero-based index of the alternative
public template<>
inline void
swap
(
Variant
& that)
Swaps two variant objects. Please refer to C++17 std::variant for more details.
- Parameters
that
a variant object to swap with