Skip to content

Commit 182ba8a

Browse files
committed
[libcxx][ranges] makes ranges::subrange a borrowed range
Differential Revision: https://reviews.llvm.org/D106207
1 parent d3454ee commit 182ba8a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

libcxx/include/__ranges/subrange.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ namespace ranges {
226226
else
227227
return __subrange.end();
228228
}
229+
230+
template<class _Ip, class _Sp, subrange_kind _Kp>
231+
inline constexpr bool enable_borrowed_range<subrange<_Ip, _Sp, _Kp>> = true;
229232
} // namespace ranges
230233

231234
using ranges::get;

libcxx/include/ranges

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ namespace std::ranges {
9393
requires is_class_v<D> && same_as<D, remove_cv_t<D>>
9494
class view_interface;
9595
96+
// [range.subrange], sub-ranges
97+
enum class subrange_kind : bool { unsized, sized };
98+
99+
template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K = see below>
100+
requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
101+
class subrange;
102+
103+
template<class I, class S, subrange_kind K>
104+
inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
105+
96106
// [range.empty], empty view
97107
template<class T>
98108
requires is_object_v<T>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
// UNSUPPORTED: libcpp-no-concepts
11+
// UNSUPPORTED: gcc-10
12+
13+
// class std::ranges::subrange;
14+
15+
#include <ranges>
16+
17+
#include "test_iterators.h"
18+
19+
namespace ranges = std::ranges;
20+
21+
static_assert(ranges::borrowed_range<ranges::subrange<int*>>);
22+
static_assert(ranges::borrowed_range<ranges::subrange<int*, int const*>>);
23+
static_assert(ranges::borrowed_range<ranges::subrange<int*, sentinel_wrapper<int*>, ranges::subrange_kind::unsized>>);

0 commit comments

Comments
 (0)