名前空間
変種
操作

std::tuple_size(std::array)

提供: cppreference.com
< cpp‎ | container‎ | array
 
 
 
 
ヘッダ <array> で定義
template< class T, std::size_t N >

struct tuple_size< std::array<T, N> > :
    std::integral_constant<std::size_t, N>

{ };
(C++11以上)

コンパイル時定数式として std::array 内の要素の数へのアクセスを提供します。

目次

std::integral_constant から���承

メンバ定数

value
[静的]
N、配列内の要素の数
(パブリック静的メンバ定数)

メンバ関数

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>

[編集]

#include <iostream>
#include <array>
 
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';
}
 
int main()
{
    std::array<float, 3> arr;
    test(arr);
}

出力:

3

[編集] 関連項目

コンパイル時に tuple のサイズを取得します
(クラステンプレートの特殊化) [edit]