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

履歴 編集

function
<ranges>

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

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

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

概要

要素数を取得する。

効果

  • (1) : return zip_.size();
  • (2) : return zip_.size();

ここで、InnerViewは説明専用のzip_view<Views...>である。

備考

zip_transform_viewのサイズは、内部で保持するzip_viewのサイズと同じで、zipする各Rangeのサイズの最小値となる。

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

int main() {
  std::vector<int> v = {1, 2, 3};
  std::array<char, 5> a = {'a', 'b', 'c', 'd', 'e'};

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

  // サイズは小さい方のサイズ(3)になる
  std::cout << "size: " << ztv.size() << std::endl;

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

出力

size: 3
const size: 3

バージョン

言語

  • C++23

処理系

参照