std::tuple_size<std::pair>
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
| ヘッダ <utility> で定義
|
||
template< class T1, class T2 > struct tuple_size<std::pair<T1, T2>>; |
(C++11以上) (C++14未満) |
|
template <class T1, class T2> struct tuple_size<std::pair<T1, T2>> : std::integral_constant<std::size_t, 2> { }; |
(C++14以上) | |
ペアに対する std::tuple_size の部分特殊化は、タプルライクな構文を使用してペアの要素数 (常に2) を取得するコンパイル時の方法を提供します。
std::integral_constant から継承
メンバ定数
value [静的] |
定数値 2 (パブリック静的メンバ定数) |
メンバ関数
operator std::size_t |
オブジェクトを std::size_t に変換します。 value を返します (パブリックメンバ関数) |
operator() (C++14) |
value を返します (パブリックメンバ関数) |
メンバ型
| 型 | 定義 |
value_type
|
std::size_t
|
type
|
std::integral_constant<std::size_t, value>
|
例
Run this code
#include <iostream>
#include <utility>
#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));
test(std::make_pair(1, 3.14));
}
出力:
3
2
関連項目
コンパイル時に tuple のサイズを取得します (クラステンプレートの特殊化) | |
array のサイズを取得します (クラステンプレートの特殊化) | |
pair の要素の型を取得します (クラステンプレートの特殊化) |