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

履歴 編集

function
<ranges>

std::ranges::zip_transform_view::begin(C++23)

constexpr auto begin();                        // (1) C++23

constexpr auto begin() const
  requires range<const InnerView> &&
           regular_invocable<
             const F&,
             range_reference_t<const Views>...
           >;                                  // (2) C++23

概要

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

効果

  • (1) : return iterator<false>(*this, zip_.begin());
  • (2) : return iterator<true>(*this, zip_.begin());

ここで、iteratorzip_transform_viewの内部で定義される説明専用のイテレータクラスであり、InnerViewは説明専用のzip_view<Views...>である。

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

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

  auto f = [](int n, char c) { return std::pair{n * 10, c}; };
  std::ranges::zip_transform_view ztv(f, v, l);

  auto it = ztv.begin();

  // 最初の要素(変換結果)
  auto [n, c] = *it;
  std::cout << n << ", " << c << std::endl;

  // 次の要素へ
  ++it;
  auto [n2, c2] = *it;
  std::cout << n2 << ", " << c2 << std::endl;
}

出力

10, a
20, b

バージョン

言語

  • C++23

処理系

参照