Defined in header <tuple> | ||||
---|---|---|---|---|
| (1) | (since C++11) | ||
| (2) | (since C++11) | ||
Defined in header <tuple> | ||||
(since C++17) (since C++17) | ||||
| (3) | (since C++11) | ||
| (4) | (since C++11) | ||
| (5) | (since C++11) |
Provides access to the number of elements in a tuple as a compile-time constant expression.
Helper variable template
| (since C++17) |
Inherited from std::integral_constant
Member constants
value [static] | sizeof...(Types) (public static member constant) |
Member functions
operator std::size_t | converts the object to std::size_t , returns value (public member function) |
operator() (C++14) | returns value (public member function) |
Member types
Type | Definition |
---|---|
value_type | std::size_t |
type | std::integral_constant<std::size_t, value> |
Notes
All specializations of std::tuple_size
satisfy UnaryTypeTrait
with BaseCharacteristic std::integral_constant<std::size_t, N>
for some N
.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <iostream> #include <tuple> template < class T> void test(T t) { int a[std::tuple_size<T>::value]; // can be used at compile time std::cout << std::tuple_size<T>::value << '\n' ; // or at run time } int main() { test(std::make_tuple(1, 2, 3.14)); } |
Output:
1 | 3 |
See also
obtains the size of an array (class template specialization) | |
(C++11) | obtains the size of a pair (class template specialization) |
tuple accesses specified element (function template) | |
obtains the type of the specified element (class template specialization) | |
std::experimental::tuple_size_v
(library fundamentals TS) | variable template alias of std::tuple_size::value (variable template) |
Please login to continue.