名前空間
変種
操作

std::ranges::iota_view<W, Bound>::size

From cppreference.com
< cpp‎ | ranges‎ | iota view
 
 
Rangesライブラリ
Rangeアダプタ
 
 
constexpr auto size() const

    requires (std::same_as<W, Bound> && /*advanceable*/<W>) ||
             (/*is-integer-like*/<W> && /*is-integer-like*/<Bound>) ||

             std::sized_sentinel_for<Bound, 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] 関連項目

rangeのサイズと等しい整数を返す
(カスタマイゼーションポイントオブジェクト)[編集]
rangeのサイズと等しい符号付き整数を返す
(カスタマイゼーションポイントオブジェクト)[編集]
English 日本語 中文(简体) 中文(繁體)