std::ranges::adjacent_view<V,N>::iterator
来自cppreference.com
<tbody>
</tbody>
template< bool Const > class /*iterator*/ |
(C++23 起) (仅用于阐述*) |
|
adjacent_view::begin 的返回类型,以及当底层视图 V 为 common_range 时 adjacent_view::end 的返回类型。
const 限定的重载返回类型 /*iterator*/<true>。非 const 限定的重载返回类型 /*iterator*/<false>。
成员类型
| 成员类型 | 定义 |
Base (私有)
|
如果 Const 为 true,则为 const V 否则为 V。(仅用于阐述的成员类型*) |
iterator_category
|
std::input_iterator_tag
|
iterator_concept
|
|
value_type
|
std::tuple</*REPEAT*/(ranges::range_value_t<Base>, N)...>;
|
difference_type
|
ranges::range_difference_t<Base>
|
数据成员
| 成员对象 | 定义 |
current_ (私有)
|
std::array<ranges::iterator_t<Base>, N>。(仅用于阐述的成员对象*) |
成员函数
| 构造一个迭代器 (公开成员函数) | |
| 访问元素 (公开成员函数) | |
| 按索引访问元素 (公开成员函数) | |
| 推进或减小各底层迭代器 (公开成员函数) |
非成员函数
| 比较底层迭代器 (函数) | |
(C++23) |
进行迭代器算术 (函数) |
(C++23) |
将对底层迭代器的解引用结果转换为相关的右值引用类型 (函数) |
(C++23) |
交换两个底层迭代器指向的对象 (函数) |
示例
运行此代码
#include <cassert>
#include <concepts>
#include <list>
#include <ranges>
#include <tuple>
#include <utility>
#include <vector>
int main()
{
auto v = std::vector{0, 1, 2, 3, 4, 5};
auto i = (v | std::views::adjacent<3>).begin();
using I = decltype(i);
static_assert(std::same_as<I::value_type, std::tuple<int, int, int>>);
static_assert(std::same_as<I::iterator_concept, std::random_access_iterator_tag>);
// 一些可用的运算符:
++i; i++; --i; i--; i += 2; i -= 2;
assert(i[2] == std::tuple(2, 3, 4));
using DI = decltype(*i);
static_assert(std::same_as<DI, std::tuple<int&, int&, int&>>);
std::get<1>(*i) = 42; // 通过迭代器 i 修改 v[1]
assert(v[1] == 42);
auto l = std::list{0, 1, 2, 3, 4, 5};
auto j = (l | std::views::adjacent<3>).begin();
using J = decltype(j);
static_assert(std::same_as<J::value_type, std::tuple<int, int, int>>);
static_assert(std::same_as<J::iterator_concept, std::bidirectional_iterator_tag>);
++j; --j; j++; j--; // 一些可用的运算符
// j += 2; j -= 2; // 错误:这些运算符
// std::ignore() = j[1]; // 对于双向迭代器不可用
}
引用
- C++23 标准(ISO/IEC 14882:2024):
- 26.7.25.3 Class template adjacent_view::iterator [range.adjacent.iterator]