std::variant_alternative,std::variant_alternative_t (3) - Linux Man Pages

std::variant_alternative,std::variant_alternative_t: std::variant_alternative,std::variant_alternative_t

NAME

std::variant_alternative,std::variant_alternative_t - std::variant_alternative,std::variant_alternative_t

Synopsis


Defined in header <variant>
template <std::size_t I, class T> (1) (since C++17)
struct variant_alternative; /* undefined */
template <size_t I, class... Types> (2) (since C++17)
struct variant_alternative<I, variant<Types...>>;
template <size_t I, class T> class variant_alternative<I, const T>;
template <size_t I, class T> class variant_alternative<I, volatile T>; (3) (since C++17)
template <size_t I, class T> class variant_alternative<I, const volatile T>;


Provides compile-time indexed access to the types of the alternatives of the possibly cv-qualified variant, combining cv-qualifications of the variant (if any) with the cv-qualifications of the alternative.
Formally,
2) meets the TransformationTrait requirements with a member typedef type equal to the type of the alternative with index I
3) meets the TransformationTrait requirements with a member typedef type that names, respectively, std::add_const_t<std::variant_alternative<I,T>>, std::add_volatile_t<std::variant_alternative<I,T>>, and std::add_cv_t<std::variant_alternative<I,T>>

Member types


Member type Definition
type the type of Ith alternative of the variant, where I must be in [0, sizeof...(Types)), otherwise the program is ill-formed.


Helper template alias


template <size_t I, class T> (since C++17)
using variant_alternative_t = typename variant_alternative<I, T>::type;

Example


 This section is incomplete
 Reason: no example


Defect reports


The following behavior-changing defect reports were applied retroactively to previously published C++ standards.


DR Applied to Behavior as published Correct behavior
LWG_2974 C++17 out-of-bounds index resulted in undefined behavior made ill-formed

See also


variant_size obtains the size of the variant's list of alternatives at compile time
variant_size_v (class template) (variable template)


(C++17)
               obtains the type of the specified element
tuple_element (class template specialization)