std::variant_alternative, std::variant_alternative_t - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::variant_alternative, std::variant_alternative_t

From cppreference.com
< cpp‎ | utility‎ | variant

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

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>>

### [edit] Member types

Member type | Definition
type | the type of `I`th alternative of the variant, where `I` must be in `[0, sizeof...(Types))`, otherwise the behavior is undefined

### [edit] Helper template alias

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

### [edit] Example

| This section is incomplete Reason: no example

### [edit] See also

variant_sizevariant_size_v (C++17) | obtains the size of the variant's list of alternatives at compile time (class template) (variable template) [edit]
tuple_element | obtains the type of the specified element (class template specialization) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/utility/variant/variant_alternative&oldid=89744"
Category:

- Todo no example