命名空间
变体
操作

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

来自 cppreference.cn
< 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 可能会拒绝整数类类型 如果可能则接受

[编辑] 参阅

返回等于范围大小的整数
(定制点对象)[编辑]
返回等于范围大小的有符号整数
(定制点对象)[编辑]