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

履歴 編集

function
<ranges>

std::ranges::chunk_by_view::base(C++23)

constexpr V base() const & requires copy_constructible<V>; // (1) C++23
constexpr V base() &&;                                     // (2) C++23

概要

メンバ変数として保持している、元となるRangeを取得する。

効果

  • (1) : return base_;
  • (2) : return std::move(base_);

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

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

  std::ranges::chunk_by_view cv{v, std::ranges::less_equal{}};

  // (1) const左辺値参照版
  const auto& base1 = cv.base();
  std::cout << "base size: " << base1.size() << std::endl;

  // (2) 右辺値参照版 
  auto base2 = std::move(cv).base();
  std::cout << "moved base size: " << base2.size() << std::endl;
}

出力

base size: 8
moved base size: 8

バージョン

言語

  • C++23

処理系

参照