std:: tuple_element <std::array>
From cppreference.net
|
ヘッダーで定義
<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() { // 配列を定義し、位置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 // tuple_elementの結果はtuple-like型のCV修飾に依存する static_assert(!std::is_same_v<T, CT>); static_assert(std::is_same_v<CT, const int>); }
関連項目
| 構造化バインディング (C++17) | 指定された名前を初期化子の部分オブジェクトまたはタプルの要素にバインドする |
|
(C++11)
|
指定された要素の型を取得する
(クラステンプレートの特殊化) |
|
(C++11)
|
pair
の要素の型を取得する
(クラステンプレートの特殊化) |