[libcxx][ranges] makes `ranges::subrange` a borrowed range

Differential Revision: https://reviews.llvm.org/D106207
This commit is contained in:
Christopher Di Bella 2021-07-17 01:35:42 +00:00
parent d3454ee8d2
commit 182ba8ab1b
3 changed files with 36 additions and 0 deletions

View File

@ -226,6 +226,9 @@ namespace ranges {
else
return __subrange.end();
}
template<class _Ip, class _Sp, subrange_kind _Kp>
inline constexpr bool enable_borrowed_range<subrange<_Ip, _Sp, _Kp>> = true;
} // namespace ranges
using ranges::get;

View File

@ -93,6 +93,16 @@ namespace std::ranges {
requires is_class_v<D> && same_as<D, remove_cv_t<D>>
class view_interface;
// [range.subrange], sub-ranges
enum class subrange_kind : bool { unsized, sized };
template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K = see below>
requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
class subrange;
template<class I, class S, subrange_kind K>
inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
// [range.empty], empty view
template<class T>
requires is_object_v<T>

View File

@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-no-concepts
// UNSUPPORTED: gcc-10
// class std::ranges::subrange;
#include <ranges>
#include "test_iterators.h"
namespace ranges = std::ranges;
static_assert(ranges::borrowed_range<ranges::subrange<int*>>);
static_assert(ranges::borrowed_range<ranges::subrange<int*, int const*>>);
static_assert(ranges::borrowed_range<ranges::subrange<int*, sentinel_wrapper<int*>, ranges::subrange_kind::unsized>>);