- ranges[meta header]
- std::ranges[meta namespace]
- chunk_by_view[meta class]
- function[meta id-type]
- cpp23[meta cpp]
constexpr V base() const & requires copy_constructible<V>; // (1) C++23
constexpr V base() &&; // (2) C++23メンバ変数として保持している、元となるRangeを取得する。
- (1) :
return base_; - (2) :
return std::move(base_);
#include <ranges>
#include <vector>
#include <functional>
#include <iostream>
int main() {
std::vector<int> v = {1, 2, 2, 3, 0, 4, 5, 2};
std::ranges::chunk_by_view cv{v, std::ranges::less_equal{}};
// (1) const左辺値参照版
const auto& base1 = cv.base();
std::cout << "base size: " << base1.size() << std::endl;
// (2) 右辺値参照版
auto base2 = std::move(cv).base();
std::cout << "moved base size: " << base2.size() << std::endl;
}- base[color ff0000]
base size: 8
moved base size: 8
- C++23
- Clang: 17 [mark verified]
- GCC: 14.0 [mark verified]
- Visual C++: 2022 Update 3 [mark verified]