std::ranges::adjacent_transform_view<V,F,N>::size
来自cppreference.com
| |
(C++23 起) | |
| |
(C++23 起) | |
返回元素数量。
令 inner_ 为 InnerView(即 ranges::adjacent_view<V,N>)类型的底层对象。
1,2) 等价于
return inner_.size();。参数
(无)
返回值
元素的数量,如果底层视图 V 小于 N 则可能为 0。
示例
运行此代码
#include <ranges>
int main()
{
constexpr static auto v = {1, 2, 3, 4, 5, 6};
auto f = [](auto...) { return 0; }; // dummy
constexpr int width1 {4};
constexpr auto view1 = v | std::views::adjacent_transform<width1>(f);
static_assert(view1.size() == 3);
static_assert(view1.size() == (v.size() - width1 + 1));
constexpr int width2 {8};
constexpr auto view2 = v | std::views::adjacent_transform<width2>(f);
// 窗口过宽,因此 view2 没有元素:
static_assert(view2.size() == 0);
}
参阅
(C++20) |
返回等于范围大小的整数 (定制点对象) |
(C++20) |
返回等于范围大小的有符号整数 (定制点对象) |