std::ranges::adjacent_view<V,N>::size
From cppreference.com
< cpp | ranges | adjacent view
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Ranges library
(C++23)(C++23)
(C++26)(C++26)
(C++23)(C++23)
(C++26)(C++26)
(C++26)(C++26)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
std::ranges::adjacent_view
adjacent_view::size
(C++26)
Member functions
Non-member functions
constexpr auto size() requires ranges::sized_range <V>;
(since C++23)
constexpr auto size() const requires ranges::sized_range <const V>;
(since C++23)
Returns the number of elements.
Let base_
be the underlying view. Equivalent to:
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);
Contents
[edit] Parameters
(none)
[edit] Return value
The number of elements, may be 0 if ranges::size (base_) is less than N.
[edit] Example
Run this code
#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)}; // window is too wide, so view2 has no elements: static_assert(view2.size() == 0); }