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

履歴 編集

function
<ranges>

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

constexpr auto begin()
  requires (!simple-view<V>);       // (1) C++20

constexpr auto begin() const
  requires range<const V> &&
           indirect_unary_predicate<
             const Pred,
             iterator_t<const V>
           >;                        // (2) C++20

概要

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

戻り値

ただし、base_は元のviewを表すメンバ変数。

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

int main() {
  std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

  std::ranges::take_while_view r{vec, [](int x) { return x < 6; }};

  auto it = r.begin();

  int x = *it;
  std::cout << x << '\n';
}

出力

1

バージョン

言語

  • C++20

処理系