名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | ranges‎ | iota_view
 
 
範圍庫 (Ranges library)
範圍介面卡 (Range adaptors)
 
 
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 起)

如果檢視有界,則返回檢視的大小。

對於 /*advanceable*//*is-integer-like*/ 的定義,請參見 advanceableis-integer-like

目錄

[編輯] 返回值

如果 WBound 中任何一個不是 整數類型別,則返回 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 可能會拒絕整數類型別 如果可能則接受

[編輯] 參閱

返回等於範圍大小的整數
(定製點物件)[編輯]
返回等於範圍大小的有符號整數
(定製點物件)[編輯]