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

履歴 編集

function
<ranges>

std::ranges::to_input_view::base(C++26)

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

constexpr V base() &&;             // (2) C++26

概要

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

効果

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

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

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

  std::ranges::to_input_view view{vec};

  // (1) コピーして取得
  std::vector<int> v1 = view.base();

  // (2) ムーブして取得
  std::ranges::to_input_view view2{vec};
  std::vector<int> v2 = std::move(view2).base();

  std::cout << v1.size() << std::endl;
  std::cout << v2.size() << std::endl;
}

出力

5
5

バージョン

言語

  • C++26

処理系