Namespaces
Variants

std::ranges::cartesian_product_view<First, Vs...>::size

cppreference.net에서
 
 
Ranges 라이브러리
범위 어댑터
 
 
constexpr /* see description */ size()
    requires /*cartesian-product-is-sized*/<First, Vs...>;
(1) (C++23부터)
constexpr /* see description */ size() const
    requires /*cartesian-product-is-sized*/<const First, const Vs...>;
(2) (C++23부터)

요소의 개수를 반환합니다. 반환 타입은 구현 정의 /*unsigned-integer-like*/ 타입 U입니다.

bases_를 기본 뷰 튜플이라고 하고, prod을 bases_에 있는 모든 범위 크기의 곱이라고 합니다.

1,2) prod를 반환합니다. prod를 반환 타입 U으로 표현할 수 없는 경우 동작이 정의되지 않습니다.

다음과 같습니다:

return [&]<std::size_t... Is>(std::index_sequence<Is...>)
{
    auto prod = static_cast<U>(1);
    prod = (static_cast<U>(ranges::size(std::get<Is>(bases_))) * ...);
    return prod;
}
(std::make_index_sequence<1U + sizeof...(Vs)>{});

매개변수

(없음)

반환값

요소의 개수, 즉 모든 기반 범위 크기의 곱입니다.

참고 사항

반환 타입은 모든 기반 범위들의 최대 크기들의 곱을 저장하기에 충분히 넓은 가장 작은 /*unsigned-integer-like*/ 타입입니다(해당 타입이 존재하는 경우).

예제

#include <ranges>
int main()
{
    constexpr static auto w = {1};
    constexpr static auto x = {2, 3};
    constexpr static auto y = {4, 5, 6};
    constexpr static auto z = {7, 8, 9, 10, 11, 12, 13};
    constexpr auto v = std::ranges::cartesian_product_view(w, x, y, z);
    static_assert(v.size() == w.size() * x.size() * y.size() * z.size() and v.size() == 42);
}

참고 항목

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