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

履歴 編集

function
<ranges>

std::ranges::enumerate_view::size(C++23)

constexpr auto size()
  requires sized_range<V>;       // (1) C++23

constexpr auto size() const
  requires sized_range<const V>; // (2) C++23

概要

要素数を取得する。

効果

  • (1) : return ranges::size(base_);
  • (2) : return ranges::size(base_);

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

int main() {
  std::vector<char> v = {'a', 'b', 'c'};

  std::ranges::enumerate_view ev(v);

  // サイズを取得
  std::cout << "size: " << ev.size() << std::endl;

  // const版も動作する
  const auto& cev = ev;
  std::cout << "const size: " << cev.size() << std::endl;
}

出力

size: 3
const size: 3

バージョン

言語

  • C++23

処理系

参照