std::meta::tuple_size
From cppreference.com
| 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
Run this code
#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
(C++26) |
obtains a reflection of element types of the tuple-like type (function) |
(C++26) |
returns the size of reflected variant's list of alternatives (function) |
(C++11) |
obtains the size of a tuple (class template specialization) |
(C++11) |
obtains the size of a pair (class template specialization) |
(C++11) |
obtains the size of an array (class template specialization) |
| obtains the size of a std::ranges::subrange (class template specialization) | |
| obtains the size of a std::complex (class template specialization) |