std::ranges::iota_view<W, Bound>::size
來自 cppreference.com
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) |
返回等於範圍大小的有符號整數 (定製點物件) |