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

履歴 編集

function
<ranges>

std::ranges::owning_view::begin(C++20)

constexpr iterator_t<R> begin(); // (1) C++20

constexpr auto begin() const
  requires range<const R>;       // (2) C++20

概要

先頭要素を指すイテレータを取得する。

効果

  • (1) : return ranges::begin(r_);
  • (2) : return ranges::begin(r_);

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

int main() {
  std::vector<int> v = {1, 2, 3, 4, 5};
  std::ranges::owning_view ov{std::move(v)};

  auto it = ov.begin();
  std::cout << "first element: " << *it << std::endl;

  // const版も使用可能
  const auto& cov = ov;
  auto const_it = cov.begin();
  std::cout << "const first element: " << *const_it << std::endl;
}

出力

first element: 1
const first element: 1

バージョン

言語

  • C++20

処理系