std::ranges::iota_view<W, Bound>::size
From cppreference.com
| constexpr auto size() const requires (std::same_as<W, Bound> && /*advanceable*/<W>) || |
(C++20以降) | |
ビューが有界である場合、そのサイズを返す。
For the definitions of /*advanceable*/ and /*is-integer-like*/, see advanceable and is-integer-like respectively.
目次 |
[edit] 戻り値
If any of W and Bound is not a integer-like type, returns to-unsigned-like (bound_ - value_ ).
Otherwise, returns (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_ ) .
[edit] 例
このコードを実行
#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 }
[edit] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 3610 | C++20 | size might reject integer-class types |
accept if possible |
[edit] 関連項目
| (C++20) |
rangeのサイズと等しい整数を返す (カスタマイゼーションポイントオブジェクト) |
| (C++20) |
rangeのサイズと等しい符号付き整数を返す (カスタマイゼーションポイントオブジェクト) |