std::ranges::views::iota, std::ranges::iota_view
|   template<std::weakly_incrementable W,          std::semiregular Bound = std::unreachable_sentinel_t>  | 
(1) | (C++20 起) | 
|   namespace views {     inline constexpr /*unspecified*/ iota = /*unspecified*/;  | 
(2) | (C++20 起) | 
E 和 F 子表达式分别表达式等价于 iota_view{E} 与 iota_view{E, F} 。表达式等价
表达式 e 表达式等价于表达式 f ,若 e 与 f 拥有相同效果,均为潜在抛出或均非潜在抛出(即 noexcept(e) == noexcept(f) ),且均为常量子表达式或均非常量子表达式。
辅助模板
|   template<std::weakly_incrementable W, std::semiregular Bound> inline constexpr bool enable_borrowed_range<ranges::iota_view<W, Bound>> = true;  | 
||
std::ranges::enable_borrowed_range 的此特化使得 iota_view 满足 borrowed_range 。
数据成员
std::ranges::iota_view::base_
|   W value_ = W(); /* exposition-only */  | 
||
当前值
std::ranges::iota_view::bound_
|   Bound bound_ = Bound(); /* exposition-only */  | 
||
边界(默认为 std::unreachable_sentinel_t )
成员函数
std::ranges::iota_view::iota_view
|   iota_view() = default;  | 
(1) | |
|   constexpr explicit iota_view(W value);  | 
(2) | |
|   constexpr iota_view(std::type_identity_t<W> value, std::type_identity_t<Bound> bound);  | 
(3) | |
value_ 与 bound_ 。value_ 。此构造函数用于创建无界 iota_view ,例如 iota(0) 产生数 0、 1、 2 ……无穷大。value_ 并以 bound 初始化 bound_ 。若 std::totally_ordered_with<W, Bound> 得到实现且 bool(value <= bound) 为 false 则行为未定义。此构造函数用于创建有界 iota_view ,例如 iota(10, 20) 产生从 10 到 19 的数。对于 (2) 与 (3) ,若 iota_view 有界(即 Bound 不是 std::unreachable_sentinel_t )且初始化 bound_ 为不可从 value 抵达的值,则行为未定义。
参数
| value | - | 开始值 | 
| bound | - | 边界 | 
std::ranges::iota_view::end
|   constexpr auto end() const;  | 
(1) | |
|   constexpr /*iterator*/ end() const requires std::same_as<W, Bound>;  | 
(2) | |
std::ranges::iota_view::size
|   constexpr auto size() const   requires (std::same_as<W, Bound> && __Advanceable<W>) ||  | 
||
若视图有界则返回视图的大小。
推导指引
|   template<class W, class Bound>     requires (!__is_integer_like<W> || !__is_integer_like<Bound> ||  | 
||
注意推导指引自身抵御有符号/无符号不匹配漏洞,如 views::iota(0, v.size()) ,其中 0 为(有符号) int 而 v.size() 为(无符号) std::size_t 。
嵌套类
|    迭代器类型  (公开成员类)  | |
   当 iota_view 有界且 Bound 与 W 不是同一类型时使用的哨位类型 (公开成员类)  | 
示例
#include <ranges> #include <iostream> int main() { for (int i : std::iota_view{1, 10}) std::cout << i << ' '; std::cout << '\n'; for (int i : std::views::iota(1, 10)) std::cout << i << ' '; std::cout << '\n'; for (int i : std::views::iota(1) | std::views::take(9)) std::cout << i << ' '; std::cout << '\n'; }
输出:
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9