std::tuple_size<std::tuple> (3) - Linux Manuals
std::tuple_size<std::tuple>: std::tuple_size<std::tuple>
NAME
std::tuple_size<std::tuple> - std::tuple_size<std::tuple>
Synopsis
Defined in header <tuple>
template< class T > (1) (since C++11)
class tuple_size; /*undefined*/
template< class... Types >
class tuple_size< std::tuple<Types...> > (2) (since C++11)
: public std::integral_constant<std::size_t, sizeof...(Types)> { };
Defined in header <tuple>
Defined in header <array> (since C++17)
Defined in header <utility> (since C++17)
Defined in header <ranges> (since C++20)
Defined in header <span> (since C++20)
template< class T >
class tuple_size<const T> (3) (since C++11)
: public std::integral_constant<std::size_t, tuple_size<T>::value> { };
template< class T >
class tuple_size< volatile T > (4) (since C++11)
: public std::integral_constant<std::size_t, tuple_size<T>::value> { };
template< class T >
class tuple_size< const volatile T > (5) (since C++11)
: public std::integral_constant<std::size_t, tuple_size<T>::value> { };
Provides access to the number of elements in a tuple as a compile-time constant expression.
In addition to being available via inclusion of the <tuple> header, the templates (3-5) are available when either of the headers <array> or <utility> are included.
All specializations of std::tuple_size satisfy UnaryTypeTrait with BaseCharacteristic std::integral_constant<std::size_t, N> for some N.
The cv-T templates (3-5) are SFINAE-friendly: if std::tuple_size<T>::value is ill-formed when treated as an unevaluated operand, (3-5) do not provide the member value. Access checking is performed as if in a context unrelated to tuple_size and T. Only the validity of the immediate context of the expression is considered. This allows
Helper variable template
template< class T > (since C++17)
inline constexpr std::size_t tuple_size_v = tuple_size<T>::value;
Inherited from std::integral_constant
Member constants
value sizeof...(Types)
[static]
Member functions
operator std::size_t (public member function)
operator() returns value
(C++14)
Member types
Type Definition
value_type std::size_t
type std::integral_constant<std::size_t, value>
Example
// Run this code
Output:
See also
std::tuple_size<std::array> (class template specialization)
std::tuple_size<std::pair> obtains the size of a pair
(C++11)
std::get(std::tuple) (function template)
tuple_element (class template specialization)