最終更新日時(UTC):
が更新

履歴 編集

function
<ranges>

std::ranges::ref_view::size(C++20)

constexpr auto size() const
  requires sized_range<R>; // (1) C++20

概要

要素数を取得する。

テンプレートパラメータ制約

戻り値

メンバ変数r_として保持しているRangeへのポインタがあるとして、以下を返す:

return ranges::size(*r_);

#include <iostream>
#include <vector>
#include <ranges>

int main() {
  std::vector<int> v = {1, 2, 3};
  auto r = std::ranges::ref_view(v);
  std::cout << r.size() << std::endl;
}

出力

3

バージョン

言語

  • C++20

処理系