std::tuple_size<std::tuple>
From cppreference.com
| ヘッダ <tuple> で定義 |
||
| template< class... Types > struct tuple_size< std::tuple<Types...> > |
(C++11以降) | |
コンパイル時定数式としてタプルの要素数にアクセスを提供します。
目次 |
[編集] ヘルパー変数テンプレート
| template< class T > constexpr std::size_t tuple_size_v = tuple_size<T>::value; |
(C++17以降) | |
std::integral_constant から継承
メンバ定数
| value [static] |
sizeof...(Types) (公開静的メンバ定数) |
メンバ関数
| operator std::size_t |
オブジェクトを std::size_t に変換し、value を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
value_type
|
std::size_t |
type
|
std::integral_constant<std::size_t, value> |
[編集] 例
このコードを実行
#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)); }
実行結果の例
3 12 16
[編集] 関連項目
| 構造化束縛 (C++17) | 指定された名前を初期化子のサブオブジェクトまたはタプル要素に束縛します |
| (C++11) |
タプルライクな型の要素数を取得する (クラステンプレート) |
| (C++11) |
pairのサイズを取得する(クラステンプレート特殊化) |
| (C++11) |
array のサイズを取得する(クラステンプレート特殊化) |
| std::ranges::subrangeのサイズを取得する (クラステンプレート特殊化) | |
| (C++11) |
tuple は指定された要素にアクセスする (関数テンプレート) |