std::meta::variant_size - cppreference.com
Namespaces
Variants

std::meta::variant_size

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval std::size_t variant_size( std::meta::info r );
(since C++26)

Returns the number of alternatives in a reflected (possibly cv-qualified) variant type represented by reflection r.

Equivalent to std::variant_size<T>::value, where T is the type represented by std::meta::dealias(r).

Parameters

r - a reflection value

Return value

The size of reflected variant type.

Exceptions

Throws std::meta::exception if r does not represent a type or type alias.

Example

#include <meta>
#include <variant>

static_assert
(
    std::meta::variant_size(^^std::variant<>) == 0 and
    std::meta::variant_size(^^std::variant<std::variant<>>) == 1 and
    std::meta::variant_size(^^std::variant<char, int>) == 2 and
    std::meta::variant_size(^^std::variant<int, char, float>) == 3 and
"");

int main() {}

See also