[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
Tue May 11 11:16:00 PDT 2021
zoecarver created this revision.
zoecarver requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Before this commit, we'd get a compilation error because the operator() overload was ambiguous.
Repository:
rG LLVM Github Monorepo
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,13 @@
inline constexpr bool std::disable_sized_range<DisabledSizeRangeWithBeginEnd> = true;
static_assert(!std::is_invocable_v<RangeSizeT, DisabledSizeRangeWithBeginEnd&>);
+struct BeginEndAndEmpty {
+ int buff[8];
+ constexpr int* begin() { return buff; }
+ constexpr int* end() { return buff + 8; }
+ constexpr bool empty() { return true; }
+};
+
constexpr bool testBeginEqualsEnd() {
BeginEndNotSizedSentinel a;
assert(std::ranges::empty(a) == true);
@@ -146,6 +153,9 @@
DisabledSizeRangeWithBeginEnd d;
assert(std::ranges::empty(d) == true);
+ BeginEndAndEmpty e;
+ assert(std::ranges::empty(e) == 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.344494.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210511/e8f888ed/attachment.bin>
More information about the libcxx-commits
mailing list