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

履歴 編集

function
<ranges>

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

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

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

概要

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

効果

入力viewV)のオブジェクトをbase_というメンバに保持するとして

  • (1) : return base_; と等価
  • (2) : return std::move(base_); と等価

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

int main() {
  using std::ranges::view;

  std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

  std::ranges::drop_view r{vec, 5};

  // (1) コピーして取得
  view auto b1 = r.base();

  // (2) ムーブして取得
  view auto b2 = std::move(r).base();

  // 得られるのは元のRangeではなく、あくまでview
  static_assert(not std::same_as<decltype(b1), std::vector<int>>);
  static_assert(    std::same_as<decltype(b1), std::ranges::ref_view<std::vector<int>>>);
  static_assert(    std::same_as<decltype(b2), std::ranges::ref_view<std::vector<int>>>);
}

出力

バージョン

言語

  • C++20

処理系