std::tuple_element<std::array>
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <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;
};
|
例
Run this code
#include <array>
#include <iostream>
#include <tuple>
#include <type_traits>
int main()
{
// define compile time constant 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
std::cout << std::boolalpha;
std::cout << std::is_same<T, int>::value << '\n';
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
std::cout << std::is_same<T, CT>::value << '\n';
std::cout << std::is_same<CT, const int>::value << '\n';
}
出力:
true
false
true
関連項目
| 指定された要素の型を取得します (クラステンプレートの特殊化) | |
pair の要素の型を取得します (クラステンプレートの特殊化) |