[libcxx-commits] [PATCH] D102263: [libcxx][ranges] Fix `ranges::empty` when begin, end, and empty members are provided.
Zoe Carver via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 13 10:08:23 PDT 2021
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98e4fd0701d0: [libcxx][ranges] Fix `ranges::empty` when begin, end, and empty members areā¦ (authored by zoecarver).
Changed prior to commit:
https://reviews.llvm.org/D102263?vs=344494&id=345200#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102263/new/
https://reviews.llvm.org/D102263
Files:
libcxx/include/__ranges/empty.h
libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp
Index: libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp
===================================================================
--- libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp
+++ libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp
@@ -133,6 +133,18 @@
inline constexpr bool std::disable_sized_range<DisabledSizeRangeWithBeginEnd> = true;
static_assert(!std::is_invocable_v<RangeSizeT, DisabledSizeRangeWithBeginEnd&>);
+struct BeginEndAndEmpty {
+ int* begin();
+ int* end();
+ constexpr bool empty() { return true; }
+};
+
+struct BeginEndAndConstEmpty {
+ int* begin();
+ int* end();
+ constexpr bool empty() const { return true; }
+};
+
constexpr bool testBeginEqualsEnd() {
BeginEndNotSizedSentinel a;
assert(std::ranges::empty(a) == true);
@@ -146,6 +158,13 @@
DisabledSizeRangeWithBeginEnd d;
assert(std::ranges::empty(d) == true);
+ BeginEndAndEmpty e;
+ assert(std::ranges::empty(e) == true);
+
+ BeginEndAndConstEmpty f;
+ assert(std::ranges::empty(f) == true);
+ assert(std::ranges::empty(std::as_const(f)) == true);
+
return true;
}
Index: libcxx/include/__ranges/empty.h
===================================================================
--- libcxx/include/__ranges/empty.h
+++ libcxx/include/__ranges/empty.h
@@ -41,6 +41,7 @@
template <class _Tp>
concept __can_compare_begin_end =
+ !__member_empty<_Tp> &&
!__can_invoke_size<_Tp> &&
requires(_Tp&& __t) {
bool(ranges::begin(__t) == ranges::end(__t));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102263.345200.patch
Type: text/x-patch
Size: 1519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210513/629a8370/attachment.bin>
More information about the libcxx-commits
mailing list