Namespaces
Variants

std::ranges::adjacent_view<V,N>:: size

From cppreference.net
Ranges library
Range adaptors
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);
}

참고 항목

범위의 크기와 동일한 정수를 반환합니다
(customization point object)
범위의 크기와 동일한 부호 있는 정수를 반환합니다
(customization point object)