名前空間
変種
操作

std::ranges::stride_view<V>::size

From cppreference.com
< cpp‎ | ranges‎ | stride view
 
 
Rangesライブラリ
Rangeアダプタ
 
 
constexpr auto size() requires ranges::sized_range<V>;
(C++23から)
constexpr auto size() const requires ranges::sized_range<const V>;
(C++23から)

要素数を返します。

基になるビューを base_、格納されているストライド値を stride_ とします。以下の式と同等です。

return /*to-unsigned-like*/(/*div-ceil*/(ranges::distance(base_), stride_));

目次

[編集] パラメータ

(なし)

[編集] 戻り値

要素数。返される値は、次の式で計算されます。

(ranges::size(base_) / stride_) + ((ranges::size(base_) % stride_ ? 1 : 0).

[編集]

#include <forward_list>
#include <ranges>
 
int main()
{
    namespace vs = std::views;
    constexpr static auto v = {1, 2, 3, 4, 5};
    static_assert
    (
        vs::stride(v, 1).size() == 5 and
        vs::stride(v, 2).size() == 3 and
        vs::stride(v, 3).size() == 2 and
        vs::stride(v, 4).size() == 2 and
        vs::stride(v, 5).size() == 1 and
        vs::stride(v, 6).size() == 1
    );
 
    std::forward_list list{v};
//  auto s = vs::stride(list, 2).size(); // Error: not a sized_range
}

[編集] 関連項目

rangeのサイズと等しい整数を返す
(カスタマイゼーションポイントオブジェクト)[編集]
rangeのサイズと等しい符号付き整数を返す
(カスタマイゼーションポイントオブジェクト)[編集]
English 日本語 中文(简体) 中文(繁體)