std::ranges::iota_view<W, Bound>::iota_view
|
iota_view() requires std::default_initializable<W> = default;
|
(1) | (C++20 起) |
|
constexpr explicit iota_view( W value );
|
(2) | (C++20 起) |
|
constexpr explicit iota_view( std::type_identity_t<W> value,
std::type_identity_t<Bound> bound ); |
(3) | (C++20 起) |
|
constexpr explicit iota_view( /*iterator*/ first, /* 见下文 */ last );
|
(4) | (C++20 起) |
构造 iota_view。
3) 以 value 初始化
value_ 并以 bound 初始化 bound_。这个构造函数用于创建有界 iota 视图,例如 iota(2, 7) 产生从 2 到 6 的数。4) 同 (3),但
value_ 以存储于 first 中存储的 W 值初始化,并且
- 如果
W和Bound为相同类型,则 last 的类型为 /*iterator*/ 且bound_以 last 中存储的W值初始化, - 否则,如果
iota_view无界(即Bound为 std::unreachable_sentinel_t),则 last 的类型为 std::unreachable_sentinel_t,而bound_被初始化为 std::unreachable_sentinel。 - 否则,last 的类型为 /*sentinel*/,而
bound_以 last 中存储的Bound值初始化。
对于 (2)、(3) 和 (4):
iota_view必须有界(即Bound为 std::unreachable_sentinel_t),或者bound_未初始化为从value_不可达的值,否则,其行为未定义。
参数
| value | - | 起始值 |
| bound | - | 边界 |
| first | - | 代表起始值的迭代器 |
| last | - | 代表边界的迭代器或哨位 |
示例
| 本节未完成 原因:Add example with non-integer template args for (1); Add overload (4) example. |
#include <cassert> #include <ranges> int main() { auto i1 = std::ranges::iota_view<int, int>(); // 重载 (1) assert(i1.empty() and i1.size() == 0); auto i2 = std::ranges::iota_view(4); // 重载 (2) assert(not i2.empty() and i2.front() == 4); auto i3 = std::ranges::iota_view(4, 8); // 重载 (3) assert(not i3.empty() and i3.front() == 4 and i3.back() == 7); }
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告 | 应用于 | 出版时的行为 | 正确行为 |
|---|---|---|---|
| LWG 3523 | C++20 | 迭代器-哨位对构造函数 (4) 可能使用错误的哨位类型 | 已更正 |
| P2711R1 | C++20 | 多参数构造函数 (3,4) 不是显式的 | 改成显式的 |