在线文档教程
C++
应用 | Utilities

std::variant_alternative_t

性病:变体[医]备选案文,STD::变式[医]替代[医]T型

Defined in header
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)

提供编译时索引访问可能的cv限定变体的类型,并结合变体%28的cv-资格(如果有%29)和备选版本的cv-资格。

正式的,

2%29TransformationTrait成员类型的要求ftype等于索引的替代类型。I

3%29TransformationTrait成员类型的要求ftype他们的名字,分别,std::add_const_t<std::variant_alternative<I,T>>,,,std::add_volatile_t<std::variant_alternative<I,T>>,和std::add_cv_t<std::variant_alternative<I,T>>

成员类型

Member typeDefinition
typethe type of Ith alternative of the variant, where I must be in [0, sizeof...(Types)), otherwise the behavior is undefined

辅助模板别名

template using variant_alternative_t = typename variant_alternative::type;(since C++17)

另见

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

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/实用程序/变体/变体[医]替代