首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::tuple_size<std::tuple>

Defined in header <tuple>

template< class T > class tuple_size; /*undefined*/

(1)

(since C++11)

template< class... Types > class tuple_size< std::tuple<Types...> > : public std::integral_constant<std::size_t, sizeof...(Types)> { };

(2)

(since C++11)

Defined in header <tuple>

Defined in header <array> Defined in header <utility>

(since C++17)(since C++17)

template< class T > class tuple_size<const T> : public std::integral_constant<std::size_t, tuple_size<T>::value> { };

(3)

(since C++11)

template< class T > class tuple_size< volatile T > : public std::integral_constant<std::size_t, tuple_size<T>::value> { };

(4)

(since C++11)

template< class T > class tuple_size< const volatile T > : public std::integral_constant<std::size_t, tuple_size<T>::value> { };

(5)

(since C++11)

以编译时常量表达式的形式提供对元组中元素数的访问。

除了通过包含<tuple>标头时,模板%283-5%29可用。<array>或<utility>包括在内。

所有的专门化std::tuple_size满足感UnaryTypeTrait带着基本特征std::integral_constant<std::size_t, N>对一些人来说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.

(since C++17)

辅助变量模板

template< class T > inline constexpr std::size_t tuple_size_v = tuple_size<T>::value;

(since C++17)

继承自STD:积分[医]常量

成员常数

value static

sizeof...(Types) (public static member constant)

成员函数

operator std::size_t

converts the object to std::size_t, returns value (public member function)

operator() (C++14)

returns value (public member function)

成员类型

Type

Definition

value_type

std::size_t

type

std::integral_constant<std::size_t, value>

二次

代码语言:javascript
复制
#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));
}

二次

产出:

二次

代码语言:javascript
复制
3

二次

另见

std::tuple_size<std::array>

obtains the size of an array (class template specialization)

std::tuple_size<std::pair> (C++11)

obtains the size of a pair (class template specialization)

std::get(std::tuple)

tuple accesses specified element (function template)

tuple_element

obtains the type of the specified element (class template specialization)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券