Namespaces
Variants

std::ranges::iota_view<W, Bound>::size

cppreference.net에서
 
 
범위 라이브러리
범위 어댑터
 
 
constexpr auto size() const
    requires (std::same_as<W, Bound> && /*advanceable*/<W>) ||
             (/*is-integer-like*/<W> && /*is-integer-like*/<Bound>) ||
             std::sized_sentinel_for<Bound, W>;
(C++20부터)

뷰가 경계가 있는 경우 뷰의 크기를 반환합니다.

/*advanceable*/ 및 /*is-integer-like*/의 정의는 advanceable 및 is-integer-like를 각각 참조하십시오.

반환값

만약 W 와 Bound 중 어느 하나라도 integer-like type 가 아닌 경우, to-unsigned-like  ( bound_ - value_  ) 를 반환합니다.

그렇지 않으면, 다음을 반환합니다 ( value_ < 0 ) ?
(
( bound_ < 0 ) ?
to-unsigned-like  ( - value_  ) - to-unsigned-like  ( - bound_  ) :
to-unsigned-like  ( bound_  ) + to-unsigned-like  ( - value_  )
) :
to-unsigned-like  ( bound_  ) - to-unsigned-like  ( value_  )
.

예제

#include <cassert>
#include <ranges>
int main()
{
    unsigned initial_value{1}, bound{5};
    auto i{std::views::iota(initial_value, bound)};
    assert(i.size() == bound - initial_value and i.size() == 4);
    auto u{std::views::iota(8)};
    // assert(u.size()); // 오류: "u"가 무한 범위이므로 size()가 존재하지 않음
}

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 3610 C++20 size 가 정수 클래스 타입을 거부할 수 있음 가능한 경우 수용

참고 항목

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