std::default_sentinel_t, std::default_sentinel
来自cppreference.com
迭代器库
迭代器概念 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迭代器原语 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
算法概念与工具 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
间接可调用概念 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
常用算法要求 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
工具 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迭代器适配器 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
流迭代器 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迭代器定制点 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
迭代器操作 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
范围访问 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
在标头
<iterator>
定义
|
||
struct
default_sentinel_t { };
|
(1) | (C++20 起) |
inline constexpr default_sentinel_t default_sentinel{};
|
(2) | (C++20 起) |
1)
default_sentinel_t
是用于表示范围结尾的空类类型。能与知晓其范围边界的迭代器类型(例如 std::counted_iterator )一同使用它。2)
default_sentinel
是
default_sentinel_t
类型常量。示例
运行此代码
#include <iterator> #include <algorithm> #include <list> #include <iostream> int main() { std::list<int> l{3,1,4,1,5,9,2,6}; std::ranges::copy(std::counted_iterator(std::begin(l), 4), std::default_sentinel, std::ostream_iterator<int>{std::cout, " "}); }
输出:
3 1 4 1
参阅
从 std::basic_istream 读取的输入迭代器 (类模板) |
|
从 std::basic_streambuf 读取的输入迭代器 (类模板) |
|
(C++20)
|
对到范围结尾距离进行跟踪的迭代器适配器 (类模板) |