std::tuple_element<std::ranges::subrange>
From cppreference.com
| ヘッダ <ranges> で定義 |
||
| template< class I, class S, ranges::subrange_kind K > struct tuple_element<0, ranges::subrange<I, S, K>>; |
(1) | (C++20以降) |
| template< class I, class S, ranges::subrange_kind K > struct tuple_element<0, const ranges::subrange<I, S, K>>; |
(2) | (C++20以降) |
| template< class I, class S, ranges::subrange_kind K > struct tuple_element<1, ranges::subrange<I, S, K>>; |
(3) | (C++20以降) |
| template< class I, class S, ranges::subrange_kind K > struct tuple_element<1, const ranges::subrange<I, S, K>>; |
(4) | (C++20以降) |
std::ranges::subrange の std::tuple_element の部分特殊化は、タプルのような構文を使用して、コンパイル時に `subrange` のイテレータまたはセンチネル型にアクセスできるようにします。これらは構造化束縛のサポートのために提供されます。
1,2) イテレータ型、つまり `I` を取得します。
3,4) センチネル型、つまり `S` を取得します。
目次 |
[編集] メンバー型
| メンバ型 | 定義 |
type
|
(1,2) I(3,4) S |
[編集] 注記
`subrange` の get 関数は、イテレータとセンチネルを値で返すため、`subrange` が const 修飾されている場合(volatile 修飾されていない場合)は、結果の型に `const` 修飾子は追加されません。
`subrange` が volatile 修飾されている場合、volatile または const volatile 型の部分特殊化が使用されるため、結果の型も volatile 修飾されます。このような使用は非推奨です。
[編集] 例
このコードを実行
#include <iterator> #include <list> #include <ranges> #include <type_traits> int main() { std::list<int> list{3, 1, 4, 1, 5, 9, 2, 6}; std::ranges::subrange subrange { std::counted_iterator{std::begin(list), 4}, std::default_sentinel }; static_assert( std::is_same_v< std::tuple_element_t<0, decltype(subrange)>, // implementation-defined type: std::counted_iterator<std::_List_iterator<int>> >); static_assert( std::is_same_v< std::tuple_element_t<1, decltype(subrange)>, std::default_sentinel_t >); }
[編集] 関連項目
| 構造化束縛 (C++17) | 指定された名前を初期化子のサブオブジェクトまたはタプル要素に束縛します |
| (C++11) |
タプルライクな型の要素型を取得する (クラステンプレート) |
| std::ranges::subrangeのサイズを取得する (クラステンプレート特殊化) |