std::ranges::iota_view<W, Bound>::迭代器
struct /*iterator*/; |
(1) | (僅作說明*) |
輔助別名模板 |
||
template< class I > using /*iota-diff-t*/ = /* 見下文 */; |
(2) | (僅作說明*) |
輔助概念 |
||
template< class I > 概念 /*decrementable*/ = |
(3) | (僅作說明*) |
template< class I > 概念 /*advanceable*/ = |
(4) | (僅作說明*) |
- 如果
I
不是整數型別,或者它是一個整數型別且 sizeof(std::iter_difference_t<I>) 大於 sizeof(I),則 /*iota-diff-t*/<I> 是 std::iter_difference_t<I>。 - 否則,如果存在寬度大於
I
的帶符號整數型別,則 /*iota-diff-t*/<I> 是該型別。 - 否則,
I
是最寬的整數型別之一,且 /*iota-diff-t*/<I> 是一個未指定的 帶符號整數類型別,其寬度不小於I
的寬度。在這種情況下,/*iota-diff-t*/<I> 是否是weakly_incrementable
的模型是未指定的。
decrementable
又是 totally_ordered
,並且該型別與其差值型別之間的 operator+=、operator-=、operator+ 和 operator- 具有共同的含義。/*iterator*/ 模型
-
random_access_iterator
,如果 W 模型advanceable
(4), -
bidirectional_iterator
,如果 W 模型decrementable
(3), -
forward_iterator
,如果 W 模型incrementable
,並且 -
input_iterator
,否則。
然而,它僅在 W
模型 incrementable
時才滿足 LegacyInputIterator,否則不滿足 LegacyInputIterator。
[編輯] 語義要求
I
僅當 I
滿足 decrementable
且其包含的所有概念都得到模型化時才模型 decrementable
,並且給定型別 I
的相等物件 a 和 b- 如果 a 和 b 都在前置和後置 operator-- 的域中(即它們是可遞減的),則以下所有條件都為 true
- std::addressof(--a) == std::addressof(a),
- bool(a-- == b),
- bool(((void)a--, a) == --b),
- bool(++(--a) == b).
- 如果 a 和 b 都在前置和後置 operator++ 的域中(即它們是可遞增的),則 bool(--(++a) == b) 為 true。
D
表示 /*iota-diff-t*/<I>。型別 I
僅當 I
滿足 advanceable
且其包含的所有概念都得到模型化時才模型 advanceable
,並且給定- 型別
I
的物件 a 和 b,以及 - 型別
D
的值 n,
使得 n 次應用 ++a 後,b 可從 a 訪問,以下所有條件均滿足
- (a += n) 等於 b。
- std::addressof(a += n) 等於 std::addressof(a)。
- I(a + n) 等於 (a += n)。
- 對於型別
D
的任意兩個正值 x 和 y,如果 I(a + D(x + y)) 是定義良好的,則 I(a + D(x + y)) 等於 I(I(a + x) + y)。 - I(a + D(0)) 等於 a。
- 如果 I(a + D(n - 1)) 是定義良好的,則 I(a + n) 等於 [](I c) { return ++c; }(I(a + D(n - 1)))。
- (b += -n) 等於 a。
- (b -= n) 等於 a。
- std::addressof(b -= n) 等於 std::addressof(b)。
- I(b - n) 等於 (b -= n)。
- D(b - a) 等於 n。
- D(a - b) 等於 D(-n)。
- bool(a <= b) 為 true。
[編輯] 巢狀型別
型別 | 定義 |
iterator_concept
|
一個 迭代器標籤,見下文 |
iterator_category (僅當 W 模型 incrementable 且/*iota-diff-t*/<W> 是整數型別時才存在) |
std::input_iterator_tag |
value_type
|
W
|
difference_type
|
/*iota-diff-t*/<W> |
[編輯] 確定迭代器概念
iterator_concept
定義如下:
- 如果
W
模型advanceable
,則iterator_concept
表示 std::random_access_iterator_tag。 - 否則,如果
W
模型decrementable
,則iterator_concept
表示 std::bidirectional_iterator_tag。 - 否則,如果
W
模型incrementable
,則iterator_concept
表示 std::forward_iterator_tag。 - 否則,
iterator_concept
表示 std::input_iterator_tag。
[編輯] 資料成員
成員 | 定義 |
W value_ |
當前值 (僅用於闡釋的成員物件*) |
[編輯] 成員函式
std::ranges::iota_view::iterator::iterator
/*iterator*/() requires std::default_initializable<W> = default; |
(1) | (C++20 起) |
constexpr explicit /*iterator*/( W value ); |
(2) | (C++20 起) |
value_
。std::ranges::iota_view::iterator::operator*
constexpr W operator*() const noexcept(std::is_nothrow_copy_constructible_v<W>); |
(C++20 起) | |
返回 value_
。
示例
#include <cassert> #include <ranges> int main() { auto it{std::views::iota(6, 9).begin()}; const int& r = *it; // binds with temporary assert(*it == 6 and r == 6); ++it; assert(*it == 7 and r == 6); }
std::ranges::iota_view::iterator::operator++
constexpr /*迭代器*/& operator++(); |
(1) | (C++20 起) |
constexpr void operator++(int); |
(2) | (C++20 起) |
constexpr /*iterator*/ operator++(int) requires std::incrementable<W>; |
(3) | (C++20 起) |
value_
; return *this;。value_
;。value_
; return tmp;。示例
#include <cassert> #include <ranges> int main() { auto it{std::views::iota(8).begin()}; assert(*it == 8); assert(*++it == 9); assert(*it++ == 9); assert(*it == 10); }
std::ranges::iota_view::iterator::operator--
constexpr /*iterator*/& operator--() requires /*decrementable*/<W>; |
(1) | (C++20 起) |
constexpr /*iterator*/operator--(int) requires /*decrementable*/<W>; |
(2) | (C++20 起) |
value_
; return *this;。value_
; return tmp;。示例
#include <cassert> #include <ranges> int main() { auto it{std::views::iota(8).begin()}; assert(*it == 8); assert(*--it == 7); assert(*it-- == 7); assert(*it == 6); }
std::ranges::iota_view::iterator::operator+=
constexpr /*iterator*/& operator+=( difference_type n ) requires /*advanceable*/<W>; |
(C++20 起) | |
更新 value_
並返回 *this
示例
#include <cassert> #include <ranges> int main() { auto it{std::views::iota(5).begin()}; assert(*it == 5); assert(*(it += 3) == 8); }
std::ranges::iota_view::iterator::operator-=
constexpr /*iterator*/& operator-=( difference_type n ) requires /*advanceable*/<W>; |
(C++20 起) | |
更新 value_
並返回 *this
示例
#include <cassert> #include <ranges> int main() { auto it{std::views::iota(6).begin()}; assert(*it == 6); assert(*(it -= -3) == 9); }
std::ranges::iota_view::iterator::operator[]
constexpr W operator[]( difference_type n ) const requires /*advanceable*/<W>; |
(C++20 起) | |
返回 W(value_
+ n)。
示例
#include <cassert> #include <ranges> int main() { auto it{std::views::iota(6).begin()}; assert(*it == 6); assert(*(it + 3) == 9); }
[編輯] 非成員函式
operator==, <, >, <=, >=, <=>(std::ranges::iota_view::iterator)
friend constexpr bool operator== ( const /*iterator*/& x, const /*iterator*/& y ) |
(1) | (C++20 起) |
friend constexpr bool operator< ( const /*iterator*/& x, const /*iterator*/& y ) |
(2) | (C++20 起) |
friend constexpr bool operator> ( const /*iterator*/& x, const /*iterator*/& y ) |
(3) | (C++20 起) |
friend constexpr bool operator<= ( const /*iterator*/& x, const /*iterator*/& y ) |
(4) | (C++20 起) |
friend constexpr bool operator>= ( const /*iterator*/& x, const /*iterator*/& y ) |
(5) | (C++20 起) |
friend constexpr bool operator<=> ( const /*iterator*/& x, const /*iterator*/& y ) |
(6) | (C++20 起) |
!=
運算子由 operator==
合成。
這些函式在普通的 非限定查詢 或 限定查詢 中不可見,並且僅當 iterator 是引數的關聯類時才能透過 引數依賴查詢 找到。
operator+(std::ranges::iota_view::iterator)
friend constexpr /*iterator*/ operator+ ( /*iterator*/ i, difference_type n ) |
(1) | (C++20 起) |
friend constexpr /*iterator*/ operator+ ( difference_type n, /*iterator*/ i ) |
(2) | (C++20 起) |
等價於 i += n; return i;。
這些函式在普通的 非限定查詢 或 限定查詢 中不可見,並且僅當 iterator 是引數的關聯類時才能透過 引數依賴查詢 找到。
operator-(std::ranges::iota_view::iterator)
friend constexpr /*iterator*/ operator- ( /*iterator*/ i, difference_type n ) |
(1) | (C++20 起) |
friend constexpr difference_type operator- ( const /*iterator*/& x, const /*iterator*/& y ) |
(2) | (C++20 起) |
D
為 difference_type
這些函式在普通的 非限定查詢 或 限定查詢 中不可見,並且僅當 iterator 是引數的關聯類時才能透過 引數依賴查詢 找到。
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
P2259R1 | C++20 | 成員 iterator_category 始終有定義 |
僅當 W 滿足 incrementable 時定義 |
LWG 3580 | C++20 | operator+ 和 operator- 的主體排除了隱式移動 | 已使其適用於隱式移動 |