class variant_alternative<I, volatile T>;
template <std::size_t I, class 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
TransformationTraitrequirements with a member typedef
type
equal to the type of the alternative with index
I
[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 program is ill-formed. [edit] Helper template alias
template <size_t I, class T>
using variant_alternative_t = typename variant_alternative<I, T>::type;
#include <variant> #include <iostream> using my_variant = std::variant<int, float>; static_assert(std::is_same_v <int, std::variant_alternative_t<0, my_variant>>); static_assert(std::is_same_v <float, std::variant_alternative_t<1, my_variant>>); // cv-qualification on the variant type propagates to the extracted alternative type. static_assert(std::is_same_v <const int, std::variant_alternative_t<0, const my_variant>>); int main() { std::cout << "All static assertions passed.\n"; }
Output:
All static assertions passed.[edit] 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 [edit] See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4