Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 1.73 KB

base.md

File metadata and controls

71 lines (51 loc) · 1.73 KB

base

  • ranges[meta header]
  • std::ranges[meta namespace]
  • as_const_view[meta class]
  • function[meta id-type]
  • cpp23[meta cpp]
constexpr V base() const & requires copy_constructible<V>;  // (1)
constexpr V base() &&;                                      // (2)
  • copy_constructible[link /reference/concepts/copy_constructible.md]

概要

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

戻り値

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

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

#include <iterator>
#include <vector>
#include <iostream>

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

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

  std::ranges::as_const_view acv{vec};

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

  // (2) ムーブして取得
  view auto b2 = std::move(acv).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>>>);
}
  • base[color ff0000]
  • same_as[link /reference/concepts/same_as.md]
  • ref_view[link /reference/ranges/ref_view.md]

出力

バージョン

言語

  • C++23

処理系

参照