std::ranges::drop_view<V>::size

来自cppreference.com
< cpp‎ | ranges‎ | drop view
 
 
 
std::ranges::drop_view
成员函数
drop_view::size
(C++20)
推导指引 (C++20)
 
constexpr auto size() requires ranges::sized_range<V>;
(1) (C++20 起)
constexpr auto size() const requires ranges::sized_range<const V>;
(2) (C++20 起)

返回元素数。

base_ 为底层视图, count_ 为存储的计数(通常为传递给构造函数的数,或若 *this 为默认构造则为 0 )。等价于

const auto s = ranges::size(base_);
const auto c = static_cast<decltype(s)>(count_);
return s < c ? 0 : s - c;

参数

(无)

返回值

元素数。

示例

#include <array>
#include <ranges>
 
int main()
{
    constexpr std::array a{42, 43, 44};
    static_assert(std::ranges::drop_view{std::views::all(a), 0}.size() == 3);
    static_assert(std::ranges::drop_view{std::views::all(a), 1}.size() == 2);
    static_assert(std::ranges::drop_view{std::views::all(a), 2}.size() == 1);
    static_assert(std::ranges::drop_view{std::views::all(a), 3}.size() == 0);
    static_assert(std::ranges::drop_view{std::views::all(a), 4}.size() == 0);
}

参阅

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