std::meta::variant_alternative
From cppreference.com
| Defined in header <meta>
|
||
consteval std::meta::info variant_alternative( std::size_t i, std::meta::info r );
|
(since C++26) | |
Returns a reflected type obtained by std::variant_alternative<I, T>::type, where T is the variant type represented by std::meta::dealias(r) and I is a constant equal to i.
If i >= std::meta::variant_size(r), the program is ill-formed.
Parameters
| i | - | an index of the alternative in the variant |
| r | - | a reflection value |
Return value
The reflected type of the variant type's element accessed by index i.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Example
Run this code
#include <meta>
#include <variant>
using my_variant = std::variant<int, float>;
static_assert
(
(^^int == variant_alternative(0, std::meta::dealias(^^my_variant))) and
(^^float == variant_alternative(1, std::meta::dealias(^^my_variant))) and
// cv-qualification on the variant type propagates to the extracted alternative type
(^^const int == variant_alternative(0, std::meta::dealias(^^const my_variant)))
);
int main() {}
