[libcxx-commits] [PATCH] D102426: [libcxx][ranges] Implement `ranges::borrowed_range`.
Zoe Carver via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 13 10:54:13 PDT 2021
zoecarver created this revision.
zoecarver added reviewers: cjdb, Quuxplusone, ldionne, EricWF.
zoecarver requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102426
Files:
libcxx/include/__ranges/concepts.h
libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp
Index: libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/ranges/range.range/borrowed_range.compile.pass.cpp
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// template<class T>
+// concept borrowed_range;
+
+#include <ranges>
+
+struct NotRange {
+ int begin() const;
+ int end() const;
+};
+
+struct Range {
+ int *begin();
+ int *end();
+};
+
+struct ConstRange {
+ int *begin() const;
+ int *end() const;
+};
+
+struct BorrowedRange {
+ int *begin() const;
+ int *end() const;
+};
+
+template<>
+inline constexpr bool std::ranges::enable_borrowed_range<BorrowedRange> = true;
+
+static_assert(!std::ranges::borrowed_range<NotRange>);
+static_assert(!std::ranges::borrowed_range<NotRange&>);
+static_assert(!std::ranges::borrowed_range<const NotRange>);
+static_assert(!std::ranges::borrowed_range<const NotRange&>);
+static_assert(!std::ranges::borrowed_range<NotRange&&>);
+
+static_assert(!std::ranges::borrowed_range<Range>);
+static_assert( std::ranges::borrowed_range<Range&>);
+static_assert(!std::ranges::borrowed_range<const Range>);
+static_assert(!std::ranges::borrowed_range<const Range&>);
+static_assert(!std::ranges::borrowed_range<Range&&>);
+
+static_assert(!std::ranges::borrowed_range<ConstRange>);
+static_assert( std::ranges::borrowed_range<ConstRange&>);
+static_assert(!std::ranges::borrowed_range<const ConstRange>);
+static_assert( std::ranges::borrowed_range<const ConstRange&>);
+static_assert(!std::ranges::borrowed_range<ConstRange&&>);
+
+static_assert( std::ranges::borrowed_range<BorrowedRange>);
+static_assert( std::ranges::borrowed_range<BorrowedRange&>);
+static_assert( std::ranges::borrowed_range<const BorrowedRange>);
+static_assert( std::ranges::borrowed_range<const BorrowedRange&>);
+static_assert( std::ranges::borrowed_range<BorrowedRange&&>);
Index: libcxx/include/__ranges/concepts.h
===================================================================
--- libcxx/include/__ranges/concepts.h
+++ libcxx/include/__ranges/concepts.h
@@ -33,6 +33,10 @@
ranges::end(__t);
};
+ template<class _Range>
+ concept borrowed_range = range<_Range> &&
+ (is_lvalue_reference_v<_Range> || enable_borrowed_range<remove_cvref_t<_Range>>);
+
// `iterator_t` defined in <__ranges/access.h>
template <range _Rp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102426.345217.patch
Type: text/x-patch
Size: 2846 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210513/e6a8ef88/attachment-0001.bin>
More information about the libcxx-commits
mailing list