[ Web Proxy ]
URL:
Viewing: https://cppreference.com/cpp/meta/tuple_size [Back]  [Original]

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

std::meta::tuple_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 tuple_size( std::meta::info r );
(since C++26)

Returns the size of reflected tuple-like type represented by reflection r.

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

Parameters

r - a reflection value

Return value

The size of reflected tuple-like type.

Exceptions

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

Example

#include <array>
#include <complex>
#include <cstddef>
#include <meta>
#include <ranges>
#include <tuple>
#include <type_traits>
#include <utility>

template<class T, std::size_t Size>
struct Arr
{
    T data[Size];
};

// Program-defined specialization of std::tuple_size:
template<class T, std::size_t Size>
struct std::tuple_size<Arr<T, Size>>
    : public std::integral_constant<std::size_t, Size>
{};

static_assert
(
    std::meta::tuple_size(^^decltype(std::tuple("_", '_', 4, 2))) == 4 and
    std::meta::tuple_size(^^decltype(std::pair("pair", 4))) == 2 and
    std::meta::tuple_size(^^decltype(std::array{1, 2, 3, 4})) == 4 and
    std::meta::tuple_size(^^decltype(std::ranges::subrange<int*>())) == 2 and
    std::meta::tuple_size(^^decltype(std::complex(4.0, 2.0))) == 2 and
    std::meta::tuple_size(^^decltype(Arr<int, 42>())) == 42
);

int main() {}

See also

obtains a reflection of element types of the tuple-like type
(function) [edit]
returns the size of reflected variant's list of alternatives
(function) [edit]
obtains the size of a tuple
(class template specialization) [edit]
obtains the size of a pair
(class template specialization) [edit]
obtains the size of an array
(class template specialization) [edit]
obtains the size of a std::ranges::subrange
(class template specialization) [edit]
obtains the size of a std::complex
(class template specialization) [edit]

Web Proxy Viewer  |  New URL  |  Original Page