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
処理系
- Clang: 21 ✅
- GCC: 15.1 ✅
- Visual C++: 2022 Update 14 ❌