From 182ba8ab1b70a1604d4d29c214261456b589e730 Mon Sep 17 00:00:00 2001 From: Christopher Di Bella Date: Sat, 17 Jul 2021 01:35:42 +0000 Subject: [PATCH] [libcxx][ranges] makes `ranges::subrange` a borrowed range Differential Revision: https://reviews.llvm.org/D106207 --- libcxx/include/__ranges/subrange.h | 3 +++ libcxx/include/ranges | 10 ++++++++ .../enable_borrowed_range.compile.pass.cpp | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 libcxx/test/std/ranges/range.utility/range.subrange/enable_borrowed_range.compile.pass.cpp diff --git a/libcxx/include/__ranges/subrange.h b/libcxx/include/__ranges/subrange.h index 8ce20bd180bf..7001c52073b6 100644 --- a/libcxx/include/__ranges/subrange.h +++ b/libcxx/include/__ranges/subrange.h @@ -226,6 +226,9 @@ namespace ranges { else return __subrange.end(); } + + template + inline constexpr bool enable_borrowed_range> = true; } // namespace ranges using ranges::get; diff --git a/libcxx/include/ranges b/libcxx/include/ranges index d662e2604e98..367ad60226d4 100644 --- a/libcxx/include/ranges +++ b/libcxx/include/ranges @@ -93,6 +93,16 @@ namespace std::ranges { requires is_class_v && same_as> class view_interface; + // [range.subrange], sub-ranges + enum class subrange_kind : bool { unsized, sized }; + + template S = I, subrange_kind K = see below> + requires (K == subrange_kind::sized || !sized_sentinel_for) + class subrange; + + template + inline constexpr bool enable_borrowed_range> = true; + // [range.empty], empty view template requires is_object_v diff --git a/libcxx/test/std/ranges/range.utility/range.subrange/enable_borrowed_range.compile.pass.cpp b/libcxx/test/std/ranges/range.utility/range.subrange/enable_borrowed_range.compile.pass.cpp new file mode 100644 index 000000000000..1c7f6e4cf2f2 --- /dev/null +++ b/libcxx/test/std/ranges/range.utility/range.subrange/enable_borrowed_range.compile.pass.cpp @@ -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 + +#include "test_iterators.h" + +namespace ranges = std::ranges; + +static_assert(ranges::borrowed_range>); +static_assert(ranges::borrowed_range>); +static_assert(ranges::borrowed_range, ranges::subrange_kind::unsized>>);