std::tuple_sizestd::tuple - cppreference.com (original) (raw)
Provides access to the number of elements in a tuple as a compile-time constant expression.
Contents
[edit] Helper variable template
| template< class T > constexpr std::size_t tuple_size_v = tuple_size<T>::value; | | (since C++17) | | ------------------------------------------------------------------------------------------------------------------ | | ------------- |
Inherited from std::integral_constant
Member constants
| | sizeof...(Types) (public static member constant) | | --------------------------------------------------- |
Member functions
| | converts the object to std::size_t, returns value (public member function) | | ----------------------------------------------------------------------------------------------------------- | | | returns value (public member function) |
Member types
[edit] Example
#include #include template void test(T value) { int a[std::tuple_size_v]; // can be used at compile time std::cout << std::tuple_size{} << ' ' // or at run time << sizeof a << ' ' << sizeof value << '\n'; } int main() { test(std::make_tuple(1, 2, 3.14)); }
Possible output:
[edit] See also
Structured binding (C++17) | binds the specified names to sub-objects or tuple elements of the initializer[edit] |
---|---|
tuple_size(C++11) | obtains the number of elements of a tuple-like type (class template) [edit] |
std::tuple_sizestd::pair(C++11) | obtains the size of a pair (class template specialization) [edit] |
std::tuple_sizestd::array(C++11) | obtains the size of an array (class template specialization) [edit] |
std::tuple_sizestd::ranges::subrange(C++20) | obtains the size of a std::ranges::subrange (class template specialization) [edit] |
get(std::tuple)(C++11) | tuple accesses specified element (function template) [edit] |