template<typename... Types>
class vccc::variant< Types >
The class template std::variant represents a type-safe union. An instance of std::variant at any given time either holds a value of one of its alternative types, or in the case of error - no value (this state is hard to achieve, see valueless_by_exception).
As with unions, if a variant holds a value of some object type T, the object representation of T is allocated directly within the object representation of the variant itself. Variant is not allowed to allocate additional (dynamic) memory.
A variant is not permitted to hold references, arrays, or the type void
. Empty variants ar also ill-formed (vccc::variant<vccc::monostate> can be used instead).
A variant is permitted to hold the same type more than once, and to hold differently cv-qualified versions of the same type.
Consistent with the behavior of unions during aggregate initialization, a default-constructed variant holds a value of its first alternative, unless that alternative is not default-constructible (in which case the variant is not default-constructible either). The helper class vccc::monostate can be used to make such variants default-constructible.
- Template Parameters
-
|
template<typename Dummy = void, std::enable_if_t< conjunction< std::is_void< Dummy >, std::is_default_constructible< type_sequence_element_type_t< 0, TypeSeq >> >::value, int > = 0> |
constexpr | variant () noexcept(std::is_nothrow_default_constructible< type_sequence_element_type_t< 0, TypeSeq >>::value) |
|
template<typename T , std::enable_if_t< conjunction< different_from< T, variant >, negation< detail::is_in_place_index< remove_cvref_t< T >> >, negation< is_specialization< remove_cvref_t< T >, in_place_type_t > >, detail::variant_has_unique_overload< T, TypeSeq > >::value, int > = 0> |
constexpr | variant (T &&t) noexcept(std::is_nothrow_constructible< detail::variant_overload_type< T, TypeSeq >, T >::value) |
|
template<typename T , typename... Args, std::enable_if_t< conjunction< bool_constant<(TypeSeq::template unique< T >)>, std::is_constructible< T, Args... > >::value , int > |
constexpr | variant (in_place_type_t< T >, Args &&... args) |
|
template<typename T , typename U , typename... Args, std::enable_if_t< conjunction< bool_constant<(TypeSeq::template unique< T >)>, std::is_constructible< T, std::initializer_list< U > &, Args... > >::value , int > |
constexpr | variant (in_place_type_t< T >, std::initializer_list< U > il, Args &&... args) |
|
template<std::size_t I, typename... Args, std::enable_if_t< conjunction< bool_constant<(I< sizeof...(Types))>, std::is_constructible< type_sequence_element_type_t< I, TypeSeq >, Args... > >::value, int > = 0> |
constexpr | variant (in_place_index_t< I >, Args &&... args) |
|
template<std::size_t I, typename U , typename... Args, std::enable_if_t< conjunction< bool_constant<(I< sizeof...(Types))>, std::is_constructible< type_sequence_element_type_t< I, TypeSeq >, std::initializer_list< U > &, Args... > >::value, int > = 0> |
constexpr | variant (in_place_index_t< I >, std::initializer_list< U > il, Args &&... args) |
|
template<typename T , std::enable_if_t< conjunction< different_from< T, variant >, detail::variant_assign_check< T, TypeSeq > >::value, int > = 0> |
constexpr variant & | operator= (T &&t) noexcept(conjunction< std::is_nothrow_assignable< detail::variant_overload_type< T, TypeSeq > &, T >, std::is_nothrow_constructible< detail::variant_overload_type< T, TypeSeq >, T > >::value) |
|
constexpr std::size_t | index () const noexcept |
|
constexpr bool | valueless_by_exception () const noexcept |
|
template<typename T , typename... Args, std::enable_if_t< conjunction< std::is_constructible< T, Args... >, bool_constant<(TypeSeq::template unique< T >)> >::value , int > |
VCCC_CONSTEXPR_AFTER_CXX20 T & | emplace (Args &&... args) |
|
template<typename T , typename U , typename... Args, std::enable_if_t< conjunction< std::is_constructible< T, std::initializer_list< U > &, Args... >, bool_constant<(TypeSeq::template unique< T >)> >::value , int > |
VCCC_CONSTEXPR_AFTER_CXX20 T & | emplace (std::initializer_list< U > il, Args &&... args) |
|
template<std::size_t I, typename... Args, std::enable_if_t< std::is_constructible< variant_alternative_t< I, variant >, Args... > ::value, int > = 0> |
VCCC_CONSTEXPR_AFTER_CXX20 variant_alternative_t< I, variant > & | emplace (Args &&... args) |
|
template<std::size_t I, typename T , typename... Args, std::enable_if_t< std::is_constructible< variant_alternative_t< I, variant >, std::initializer_list< T > &, Args... > ::value, int > = 0> |
VCCC_CONSTEXPR_AFTER_CXX20 variant_alternative_t< I, variant > & | emplace (std::initializer_list< T > il, Args &&... args) |
|
constexpr void | swap (variant &rhs) noexcept(conjunction< std::is_nothrow_move_constructible< Types >..., is_nothrow_swappable< Types >... >::value) |
|
template<typename Visitor > |
constexpr decltype(auto) | visit (Visitor &&vis) & |
|
template<typename Visitor > |
constexpr decltype(auto) | visit (Visitor &&vis) const & |
|
template<typename Visitor > |
constexpr decltype(auto) | visit (Visitor &&vis) && |
|
template<typename Visitor > |
constexpr decltype(auto) | visit (Visitor &&vis) const && |
|
template<typename R , typename Visitor > |
constexpr R | visit (Visitor &&vis) & |
|
template<typename R , typename Visitor > |
constexpr R | visit (Visitor &&vis) const & |
|
template<typename R , typename Visitor > |
constexpr R | visit (Visitor &&vis) && |
|
template<typename R , typename Visitor > |
constexpr R | visit (Visitor &&vis) const && |
|