名前空間
変種
操作

std::tuple_element<std::array>

From cppreference.com
< cpp‎ | container‎ | array
 
 
 
 
ヘッダー <array> で定義
template< std::size_t I, class T, std::size_t N >
struct tuple_element< I, std::array<T, N> >;
(C++11以降)

配列の要素の型に、タプルライクなインターフェースを使用してコンパイル時にインデックスアクセスを提供します。

目次

[編集] メンバ型

メンバ型 定義
type 配列の要素の型

[編集] 実装例

template<std::size_t I, class T>
struct tuple_element;
 
template<std::size_t I, class T, std::size_t N>
struct tuple_element<I, std::array<T,N>>
{
    using type = T;
};

[編集]

#include <array>
#include <tuple>
#include <type_traits>
 
int main()
{
    // define array and get the type of the element at position 0
    std::array<int, 10> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    using T = std::tuple_element<0, decltype(data)>::type; // int
    static_assert(std::is_same_v<T, int>);
 
    const auto const_data = data;
    using CT = std::tuple_element<0, decltype(const_data)>::type; // const int
 
    // the result of tuple_element depends on the cv-qualification of the tuple-like type
    static_assert(!std::is_same_v<T, CT>);
    static_assert(std::is_same_v<CT, const int>);
}

[編集] 関連

構造化束縛 (C++17) 指定された名前を初期化子のサブオブジェクトまたはタプル要素に束縛します[編集]
指定された要素の型を取得する
(クラステンプレート特殊化) [編集]
pairの要素の型を取得する
(クラステンプレート特殊化) [編集]
English 日本語 中文(简体) 中文(繁體)