This class is a replacement for C++17 std::variant. More...
#include <cvb/shims/variant.hpp>
Public Member Functions | |
variant () noexcept | |
Default ctor creating a variant with default value of the first alternative type. | |
~variant () noexcept | |
Destructor. | |
variant (const variant &rhs) | |
Copy ctor. More... | |
variant (variant &&rhs) noexcept | |
Move ctor. More... | |
variant & | operator= (const variant &rhs) |
Copy operator. More... | |
variant & | operator= (variant &&rhs) |
Move operator. More... | |
template<class T , typename std::enable_if<!std::is_same< T, variant & >::value, int >::type = 0> | |
variant (T &&value) | |
Ctor from an object of supported type T . More... | |
template<class T , typename std::enable_if<!std::is_same< T, variant & >::value, int >::type = 0> | |
variant & | operator= (T &&value) |
Assignment from an object of supported type T . More... | |
template<size_t I, class... ARGS> | |
variant_alternative< I, variant< TS... > >::type & | emplace (ARGS &&... args) |
Emplaces an object as alternative at index I . More... | |
template<class T , class... ARGS> | |
T & | emplace (ARGS &&... args) |
Emplaces an object as a type T . More... | |
size_t | index () const noexcept |
Gets the zero-based index of the alternative held by this instance. | |
void | swap (variant &other) |
Swaps the content of this variant with the other one. More... | |
bool | valueless_by_exception () const noexcept |
Returns false only if this instance holds a value. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
static const constexpr size_t | variant_alternatives_size_v = variant_size<T>::value |
Get the number of alternatives in a variant. | |
template<size_t I, class... TS> | |
const variant_alternative_t< I, variant< TS... > > & | get (const variant< TS... > &var) |
template<size_t I, class... TS> | |
variant_alternative_t< I, variant< TS... > > & | get (variant< TS... > &var) |
template<size_t I, class... TS> | |
variant_alternative_t< I, variant< TS... > > | get (variant< TS... > &&var) |
template<class T , class... TS> | |
const T & | get (const variant< TS... > &var) |
template<class T , class... TS> | |
T & | get (variant< TS... > &var) |
template<class T , class... TS> | |
T | get (variant< TS... > &&var) |
template<size_t I, class... TS> | |
std::add_pointer< variant_alternative_t< I, variant< TS... > > >::type | get_if (variant< TS... > *pvar) noexcept |
template<class T , class... TS> | |
std::add_pointer< constT >::type | get_if (const variant< TS... > *pvar) noexcept |
template<class T , class... TS> | |
std::add_pointer< T >::type | get_if (variant< TS... > *pvar) noexcept |
template<class T , class... TS> | |
bool | holds_alternative (const variant< TS... > &var) noexcept |
Gets whether the Shims::variant var holds an instance of type T . More... | |
template<class VISITOR , class VARIANT > | |
auto | visit (VISITOR &&visitor, VARIANT &&var) -> decltype(visitor(get< 0 >(var))) |
Visits the given Shims::variant var. Cvb::Shims::visit can only visit one variant (not multiple like std::visit). More... | |
template<class... TS> | |
bool | operator== (const variant< TS... > &lhs, const variant< TS... > &rhs) |
Equality operator for Shims::variant objects. More... | |
template<class... TS> | |
bool | operator!= (const variant< TS... > &lhs, const variant< TS... > &rhs) |
Inequality operator for Shims::variant objects. More... | |
template<class... TS> | |
bool | operator< (const variant< TS... > &lhs, const variant< TS... > &rhs) |
Less than operator for Shims::variant objects. More... | |
template<class... TS> | |
bool | operator<= (const variant< TS... > &lhs, const variant< TS... > &rhs) |
Less-than or equal operator for Shims::variant object. More... | |
template<class... TS> | |
bool | operator> (const variant< TS... > &lhs, const variant< TS... > &rhs) |
Greater-than operator for Shims::variant object. More... | |
template<class... TS> | |
bool | operator>= (const variant< TS... > &lhs, const variant< TS... > &rhs) |
Greater-than or equal operator for Shims::variant object. More... | |
This class is a replacement for C++17 std::variant.
|
inline |
Ctor from an object of supported type T
.
T | Type of value to set. |
[in] | value | The value to store in this variant. |
variant_alternative< I, variant< TS... > >::type & emplace | ( | ARGS &&... | args | ) |
Emplaces an object as alternative at index I
.
I | Index of alternative to use. |
[in] | args | Arguments to be forwarded to alternative's ctor. |
|
inline |
Emplaces an object as a type T
.
T | Type of alternative to use. |
[in] | args | Arguments to be forwarded to alternative's ctor. |
Copy operator.
[in] | rhs | Object to copy. |
|
inline |
Assignment from an object of supported type T
.
T | Type of value to set. |
[in] | value | The value to store in this variant. |
Move operator.
[in] | rhs | Object to move. |
void swap | ( | variant< TS > & | other | ) |
Swaps the content of this variant with the other one.
[in] | other | Other object to swap content with. |
|
inlinenoexcept |
Returns false only if this instance holds a value.
|
related |
Gets the value of the given Shims::variant var as the alternative with index I
.
I | Index of alternative to extract. |
[in] | var | Variant to get the value of. |
bad_variant_access | thrown if I is unequal variant::index(). |
|
related |
Gets the value of the given Shims::variant var as the alternative with type T
.
T | Type to query. |
[in] | var | Variant to get the value of. |
bad_variant_access | thrown if T is not a variant alternative. |
|
related |
Gets the value of the given Shims::variant var as the alternative with index I
.
I | Index of alternative to extract. |
[in] | var | Variant to get the value of. |
bad_variant_access | thrown if I is unequal variant::index(). |
|
related |
Gets the value of the given Shims::variant var as the alternative with type T
.
T | Type to query. |
[in] | var | Variant to get the value of. |
bad_variant_access | thrown if T is not a variant alternative. |
|
related |
Gets the value of the given Shims::variant var as the alternative with index I
.
I | Index of alternative to extract. |
[in] | var | Variant to get the value of. |
bad_variant_access | thrown if I is unequal variant::index(). |
|
related |
Gets the value of the given Shims::variant var as the alternative with type T
.
T | Type to query. |
[in] | var | Variant to get the value of. |
bad_variant_access | thrown if T is not a variant alternative. |
|
related |
Tries to get the value of the given Shims::variant pointer pvar as the alternative with type T
.
T | Type to query. |
[in] | pvar | Variant to get the value of. |
T
.
|
related |
Tries to get the value of the given Shims::variant pointer pvar as the alternative with index I
.
I | Index of alternative to extract. |
[in] | pvar | Variant to get the value of. |
I
is unequal pvar object's index().
|
related |
Tries to get the value of the given Shims::variant pointer pvar as the alternative with type T
.
T | Type to query. |
[in] | pvar | Variant to get the value of. |
T
.
|
related |
Gets whether the Shims::variant var holds an instance of type T
.
T | Type to test. |
[in] | var | Variant to check. |
T
; false if not. Inequality operator for Shims::variant objects.
[in] | lhs | Left hand side object. |
[in] | rhs | Right hand side object. |
Less than operator for Shims::variant objects.
[in] | lhs | Left hand side object. |
[in] | rhs | Right hand side object. |
Less-than or equal operator for Shims::variant object.
[in] | lhs | Left hand side object. |
[in] | rhs | Right hand side object. |
Equality operator for Shims::variant objects.
[in] | lhs | Left hand side object. |
[in] | rhs | Right hand side object. |
Greater-than operator for Shims::variant object.
[in] | lhs | Left hand side object. |
[in] | rhs | Right hand side object. |
Greater-than or equal operator for Shims::variant object.
[in] | lhs | Left hand side object. |
[in] | rhs | Right hand side object. |
|
related |
Visits the given Shims::variant var. Cvb::Shims::visit can only visit one variant (not multiple like std::visit).
VISITOR | Callable that get the value of the variant as argument. |
TS | Parameter pack of the Shims::variant alternatives. |
[in] | visitor | Callable to visit the variant var. |
[in] | var | Variant to visit. |