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

履歴 編集

function
<ranges>

std::ranges::reverse_view::base(C++20)

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

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

概要

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

効果

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

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

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

  std::ranges::reverse_view rv(vec);

  // (1) コピーして取得
  auto base1 = rv.base();
  static_assert(std::same_as<decltype(base1), std::ranges::ref_view<std::vector<int>>>);

  // (2) ムーブして取得
  auto base2 = std::move(rv).base();
  static_assert(std::same_as<decltype(base2), std::ranges::ref_view<std::vector<int>>>);

  // 取得したviewを使用(元の順序)
  for (int n : base1) {
    std::cout << n << " ";
  }
  std::cout << std::endl;
}

出力

1 2 3 4 5 

バージョン

言語

  • C++20

処理系

参照