- ranges[meta header]
- std::ranges[meta namespace]
- as_rvalue_view[meta class]
- function[meta id-type]
- cpp23[meta cpp]
constexpr auto end()
requires (!simple-view <V>); // (1) C++23
constexpr auto end() const
requires range<const V>; // (2) C++23番兵を取得する。
メンバ変数r_として保持しているRangeへのポインタがあるとして、以下を返す:
if constexpr (common_range<V>) {
return std::move_iterator(ranges::end(base_));
}
else {
return std::move_sentinel(ranges::end(base_));
}#include <iostream>
#include <vector>
#include <ranges>
#include <string>
int main() {
std::vector<std::string> v = {"one", "two", "three"};
auto r = std::ranges::as_rvalue_view(v);
auto it = r.begin();
auto end = r.end();
while (it != end) {
std::string x = *it; // ここでムーブされる
std::cout << x << std::endl;
++it;
}
}- end[color ff0000]
- begin()[link begin.md]
one
two
three
- C++23
- Clang: 17 [mark verified]
- GCC: 13 [mark verified]
- Visual C++: 2022 Update 4 [mark verified]