std::ranges::repeat_view<W, Bound>::iterator
来自 cppreference.cn
< cpp | ranges | repeat view
struct /*iterator*/; |
(仅作说明*) | |
ranges::repeat_view<W, Bound>::iterator 是 ranges::repeat_view<W, Bound> 的 begin() 和 end() 返回的迭代器类型。
[编辑] 嵌套类型
仅用于说明的类型 | |
| 类型 | 定义 |
index-type
|
std::conditional_t<std::same_as<Bound, std::unreachable_sentinel_t>, std::ptrdiff_t, Bound>(仅供说明的成员类型*) |
迭代器属性类型 | |
| 类型 | 定义 |
iterator_concept
|
std::random_access_iterator_tag |
iterator_category
|
std::random_access_iterator_tag |
value_type
|
W
|
difference_type |
std::conditional_t<is-signed-integer-like <index-type >, index-type , iota-diff-t <index-type >> |
[编辑] 数据成员
| 成员 | 定义 |
const W* value_ |
指向要重复的值的指针 (仅用于阐释的成员对象*) |
index-type current_ |
当前位置 (仅用于阐释的成员对象*) |
[编辑] 成员函数
std::ranges::repeat_view::iterator::iterator
| /*iterator*/() = default; |
(1) | (C++23 起) |
constexpr explicit /*iterator*/ ( const W* value, /*index-type*/ b = /*index-type*/() ); |
(2) | (C++23 起) (仅作说明*) |
构造一个迭代器。重载 (2) 由 ranges::repeat_view 的 begin() 和 end() 调用。
std::ranges::repeat_view::iterator::operator*
| constexpr const W& operator*() const noexcept; |
(C++23 起) | |
返回 *value_。
std::ranges::repeat_view::iterator::operator[]
| constexpr const W& operator[]( difference_type n ) const noexcept; |
(C++23 起) | |
返回 *(*this + n)。
std::ranges::repeat_view::iterator::operator++
| constexpr /*迭代器*/& operator++(); |
(1) | (C++23 起) |
| constexpr void operator++(int); |
(2) | (C++23 起) |
1) 等价于 ++
current_ ; return *this;。2) 等价于 auto tmp = *this; ++*this; return tmp;。
std::ranges::repeat_view::iterator::operator--
| constexpr /*iterator*/& operator--(); |
(1) | (C++23 起) |
| constexpr /*iterator*/ operator--(int); |
(2) | (C++23 起) |
1) 等价于 --
current_ ; return *this;。2) 等价于 auto tmp = *this; --*this; return tmp;。
std::ranges::repeat_view::iterator::operator+=
| constexpr /*iterator*/& operator+=( difference_type n ); |
(C++23 起) | |
等价于 current_ += n; return *this;。
如果 Bound 不是 std::unreachable_sentinel_t 且 current_ + n 为负,则行为未定义。
std::ranges::repeat_view::iterator::operator-=
| constexpr /*iterator*/& operator-=( difference_type n ); |
(C++23 起) | |
等价于 current_ -= n; return *this;。
如果 Bound 不是 std::unreachable_sentinel_t 且 current_ - n 为负,则行为未定义。
[编辑] 非成员函数
operator==, <=>(std::ranges::repeat_view::iterator)
| friend constexpr bool operator== ( const /*iterator*/& x, const /*iterator*/& y ); |
(1) | (C++23 起) |
| friend constexpr auto operator<=> ( const /*iterator*/& x, const /*iterator*/& y ); |
(2) | (C++23 起) |
!= 运算符由 operator== 合成。
operator+(std::ranges::repeat_view::iterator)
| friend constexpr /*iterator*/ operator+ ( /*iterator*/ i, difference_type n ); |
(1) | (C++23 起) |
| friend constexpr /*iterator*/ operator+ ( difference_type n, /*iterator*/ i ); |
(2) | (C++23 起) |
等价于 i += n; return i;。
operator-(std::ranges::repeat_view::iterator)
| friend constexpr /*iterator*/ operator- ( /*iterator*/ i, difference_type n ); |
(1) | (C++23 起) |
| friend constexpr difference_type operator- ( const /*iterator*/& x, const /*iterator*/& y ); |
(2) | (C++23 起) |
1) 等价于 i -= n; return i;。
2) 返回 static_cast<
difference_type>(x.current_ ) - static_cast<difference_type>(y.current_ )。[编辑] 注意
iterator 始终是 random_access_iterator。