std::tuple_size<std::tuple>
From cppreference.com
 
 
 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Utilities library 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
  
 
 
 Type support (basic types, RTTI)
 Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
 Coroutine support (C++20)
 Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
  (C++20)(C++20)(C++20)
  (C++20)(C++20)(C++20)
 General utilities
 Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
  (C++20)(C++20)(C++20)
(C++20)
 Swap and type operations 
 Common vocabulary types
std::tuple 
 
 
 
 
 
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
(C++23)
tuple_size<std::tuple>
(C++23)
(C++23)
 Deduction guides (C++17)
Defined in header 
 
 
<tuple> 
 template< class... Types >
 
 (since C++11) 
struct tuple_size< std::tuple <Types...> >
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) 
constexpr std::size_t tuple_size_v = tuple_size<T>::value;
Inherited from std::integral_constant
Member constants
value
[static]
sizeof...(Types) (public static member constant)
Member functions
operator()
(C++14)
(public member function)
Member types
 Type
 Definition
value_type
 std::size_t 
type
 std::integral_constant <std::size_t, value>
[edit] Example
Run this code
#include <iostream> #include <tuple> template <class T> void test(T value) { int a[std::tuple_size_v <T>]; // can be used at compile time std::cout << std::tuple_size <T>{} << ' ' // or at run time << sizeof a << ' ' << sizeof value << '\n'; } int main() { test(std::make_tuple (1, 2, 3.14)); }
Possible output:
3 12 16
[edit] See also
 Structured binding (C++17)
 binds the specified names to sub-objects or tuple elements of the initializer[edit]