std::ranges::adjacent_view<V,N>:: size
From cppreference.net
<
cpp
|
ranges
|
adjacent view
C++
Ranges library
|
||||||||||||||||||||||
| Range primitives | |||||||
|
|||||||
| Range concepts | |||||||||||||||||||
|
|||||||||||||||||||
| Range factories | |||||||||
|
|||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||
| Helper items | |||||||||||||||||
|
|
||||||||||||||||
std::ranges::adjacent_view
| Member functions | ||||
|
adjacent_view::size
|
||||
|
(C++26)
|
||||
| Iterator | ||||
| Member functions | ||||
| Non-member functions | ||||
| Sentinel | ||||
| Member functions | ||||
| Non-member functions | ||||
|
constexpr
auto
size
(
)
requires
ranges::
sized_range
<
V
>
;
|
(C++23以降) | |
|
constexpr
auto
size
(
)
const
requires
ranges::
sized_range
<
const
V
>
;
|
(C++23以降) | |
要素の数を返します。
base_
を基底ビューとする。次と等価:
using SizeType = decltype(ranges::size(base_)); using CommonType = ranges::common_type_t<SizeType, std::size_t>; auto size = static_cast<CommonType>(ranges::size(base_)); size -= std::min<CommonType>(size, N - 1); return static_cast<SizeType>(size);
目次 |
パラメータ
(なし)
戻り値
要素の数は、 0 になる可能性があります。これは、 ranges:: size ( base_ ) が N より小さい場合です。
例
このコードを実行
#include <ranges> int main() { constexpr static auto v = {1, 2, 3, 4, 5, 6}; constexpr int width1 {4}; constexpr auto view1 {std::views::adjacent<width1>(v)}; static_assert(view1.size() == 3); static_assert(view1.size() == (v.size() - width1 + 1)); constexpr int width2 {8}; constexpr auto view2 {std::views::adjacent<width2>(v)}; // ウィンドウが広すぎるため、view2には要素がありません: static_assert(view2.size() == 0); }
関連項目
|
(C++20)
|
範囲のサイズに等しい整数を返す
(カスタマイゼーションポイントオブジェクト) |
|
(C++20)
|
範囲のサイズに等しい符号付き整数を返す
(カスタマイゼーションポイントオブジェクト) |