constexpr V base() const &
requires copy_constructible<V>; // (1) C++20
constexpr V base() &&; // (2) C++20
概要
メンバ変数として保持している、元のview
を取得する。
効果
入力view
(V
)のオブジェクトをbase_
というメンバに保持するとして
- (1) :
return base_;
と等価 - (2) :
return std::move(base_);
と等価
例
#include <ranges>
#include <vector>
#include <string>
#include <iostream>
int main() {
using std::ranges::view;
std::vector<std::string> words = {"hello", "world", "join"};
std::ranges::join_view r{words};
// (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<std::string>>);
static_assert( std::same_as<decltype(b1), std::ranges::ref_view<std::vector<std::string>>>);
static_assert( std::same_as<decltype(b2), std::ranges::ref_view<std::vector<std::string>>>);
}
出力
バージョン
言語
- C++20
処理系
- Clang: 13.0.0 ✅
- GCC: 10.1.0 ✅
- ICC: ?
- Visual C++: 2019 Update 10 ✅