std::ranges::iota_view<W, Bound>::size
来自 cppreference.cn
constexpr auto size() const requires (std::same_as<W, Bound> && /*advanceable*/<W>) || |
(C++20 起) | |
如果视图有界,则返回视图的大小。
对于 /*advanceable*/ 和 /*is-integer-like*/ 的定义,请参见 advanceable
和 is-integer-like。
目录 |
[编辑] 返回值
如果 W
和 Bound
中任何一个不是 整数类类型,则返回 to-unsigned-like
(bound_
-
value_
)。
否则,返回 (value_
< 0) ?
(
(bound_
< 0) ?
to-unsigned-like
(-value_
) -
to-unsigned-like
(-bound_
) :
to-unsigned-like
(bound_
) +
to-unsigned-like
(-value_
)
) :
to-unsigned-like
(bound_
) -
to-unsigned-like
(value_
) 。
[编辑] 示例
运行此代码
#include <cassert> #include <ranges> int main() { unsigned initial_value{1}, bound{5}; auto i{std::views::iota(initial_value, bound)}; assert(i.size() == bound - initial_value and i.size() == 4); auto u{std::views::iota(8)}; // assert(u.size()); // Error: size() is not present since “u” is unbounded }
[编辑] 缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
缺陷报告 | 应用于 | 发布时的行为 | 正确的行为 |
---|---|---|---|
LWG 3610 | C++20 | size 可能会拒绝整数类类型 |
如果可能则接受 |
[编辑] 参阅
(C++20) |
返回等于范围大小的整数 (定制点对象) |
(C++20) |
返回等于范围大小的有符号整数 (定制点对象) |