std::ranges::adjacent_view<V,N>::size
cppreference.net에서
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)
|
범위의 크기와 동일한 정수를 반환합니다
(customization point object) |
|
(C++20)
|
범위의 크기와 동일한 부호 있는 정수를 반환합니다
(customization point object) |