std::tuple_element<std::ranges::subrange>
來自 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::tuple_element 對於 std::ranges::subrange 的部分特化提供了使用類元組語法對 subrange
的迭代器或哨位型別的編譯時訪問。它們被提供以支援結構化繫結。
1,2) 獲得迭代器型別,即
I
。3,4) 獲得哨位型別,即
S
。目錄 |
[編輯] 成員型別
成員型別 | 定義 |
型別
|
(1,2) I (3,4) S |
[編輯] 注意
因為 subrange
的 get
函式以值返回迭代器和哨位,所以當 subrange
是 const 限定(但非 volatile 限定)時,不會給結果型別新增 const 限定符。
如果 subrange
是 volatile 限定的,結果型別也會是 volatile 限定的,因為會使用 volatile 或 const 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 的大小 (類模板特化) |