Namespaces
Variants

std::ranges::cartesian_product_view<まず、Vs...>::size

ja.cppreference.net から
 
 
レンジライブラリ
レンジアダプタ
 
 
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);
}

関連項目

範囲のサイズに等しい整数を返す
(カスタマイゼーションポイントオブジェクト)
範囲のサイズに等しい符号付き整数を返す
(カスタマイゼーションポイントオブジェクト)