-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++][ranges] LWG4035: single_view
should provide empty
#98371
Merged
Zingam
merged 5 commits into
llvm:main
from
H-G-Hristov:hgh/libcxx/LWG4035-single_view-should-provide-empty
Jul 16, 2024
Merged
[libc++][ranges] LWG4035: single_view
should provide empty
#98371
Zingam
merged 5 commits into
llvm:main
from
H-G-Hristov:hgh/libcxx/LWG4035-single_view-should-provide-empty
Jul 16, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This recreates an earlier, unreviewed PR, which I destroyed disastrously while rebasing: |
H-G-Hristov
changed the title
[libc++][ranges] LWG4035: single_view should provide empty
[libc++][ranges] LWG4035: Jul 10, 2024
single_view
should provide empty
llvmbot
added
the
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
label
Jul 10, 2024
@llvm/pr-subscribers-libcxx Author: Hristo Hristov (H-G-Hristov) ChangesImplements: https://wg21.link/LWG4035 Full diff: https://github.com/llvm/llvm-project/pull/98371.diff 3 Files Affected:
diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 540c6a8dd4f47..f9a70aee1bf46 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -53,7 +53,7 @@
"`4025 <https://wg21.link/LWG4025>`__","Move assignment operator of ``std::expected<cv void, E>`` should not be conditionally deleted","Tokyo March 2024","","",""
"`4030 <https://wg21.link/LWG4030>`__","Clarify whether arithmetic expressions in ``[numeric.sat.func]`` are mathematical or C++","Tokyo March 2024","|Nothing To Do|","",""
"`4031 <https://wg21.link/LWG4031>`__","``bad_expected_access<void>`` member functions should be ``noexcept``","Tokyo March 2024","|Complete|","16.0",""
-"`4035 <https://wg21.link/LWG4035>`__","``single_view`` should provide ``empty``","Tokyo March 2024","","","|ranges|"
+"`4035 <https://wg21.link/LWG4035>`__","``single_view`` should provide ``empty``","Tokyo March 2024","|Complete|","19.0","|ranges|"
"`4036 <https://wg21.link/LWG4036>`__","``__alignof_is_defined`` is only implicitly specified in C++ and not yet deprecated","Tokyo March 2024","","",""
"`4037 <https://wg21.link/LWG4037>`__","Static data members of ``ctype_base`` are not yet required to be usable in constant expressions","Tokyo March 2024","","",""
"`4038 <https://wg21.link/LWG4038>`__","``std::text_encoding::aliases_view`` should have constexpr iterators","Tokyo March 2024","","",""
diff --git a/libcxx/include/__ranges/single_view.h b/libcxx/include/__ranges/single_view.h
index f91c7c3526367..45244f34994d7 100644
--- a/libcxx/include/__ranges/single_view.h
+++ b/libcxx/include/__ranges/single_view.h
@@ -70,6 +70,8 @@ class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS single_view : public view_interface<s
_LIBCPP_HIDE_FROM_ABI constexpr const _Tp* end() const noexcept { return data() + 1; }
+ _LIBCPP_HIDE_FROM_ABI static constexpr bool empty() noexcept { return false; }
+
_LIBCPP_HIDE_FROM_ABI static constexpr size_t size() noexcept { return 1; }
_LIBCPP_HIDE_FROM_ABI constexpr _Tp* data() noexcept { return __value_.operator->(); }
diff --git a/libcxx/test/std/ranges/range.factories/range.single.view/empty.pass.cpp b/libcxx/test/std/ranges/range.factories/range.single.view/empty.pass.cpp
new file mode 100644
index 0000000000000..7e6ff015ea9a4
--- /dev/null
+++ b/libcxx/test/std/ranges/range.factories/range.single.view/empty.pass.cpp
@@ -0,0 +1,64 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// static constexpr bool empty() noexcept;
+
+#include <cassert>
+#include <concepts>
+#include <ranges>
+#include <utility>
+
+#include "test_macros.h"
+
+struct Empty {};
+struct BigType {
+ char buffer[64] = {10};
+};
+
+template <typename T>
+constexpr void test_empty(T value) {
+ using SingleView = std::ranges::single_view<T>;
+
+ {
+ std::same_as<bool> decltype(auto) result = SingleView::empty();
+ assert(result == false);
+ static_assert(noexcept(SingleView::empty()));
+ }
+
+ {
+ SingleView sv{value};
+
+ std::same_as<bool> decltype(auto) result = std::ranges::empty(sv);
+ assert(result == false);
+ static_assert(noexcept(std::ranges::empty(sv)));
+ }
+ {
+ const SingleView sv{value};
+
+ std::same_as<bool> decltype(auto) result = std::ranges::empty(sv);
+ assert(result == false);
+ static_assert(noexcept(std::ranges::empty(std::as_const(sv))));
+ }
+}
+
+constexpr bool test() {
+ test_empty<int>(92);
+ test_empty<Empty>(Empty{});
+ test_empty<BigType>(BigType{});
+
+ return true;
+}
+
+int main(int, char**) {
+ test();
+ static_assert(test());
+
+ return 0;
+}
|
ldionne
approved these changes
Jul 16, 2024
@ldionne Thank you! |
sayhaan
pushed a commit
to sayhaan/llvm-project
that referenced
this pull request
Jul 16, 2024
…98371) Summary: Implements: https://wg21.link/LWG4035 - https://eel.is/c++draft/range.single.view Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D59822401
H-G-Hristov
deleted the
hgh/libcxx/LWG4035-single_view-should-provide-empty
branch
July 19, 2024 15:39
yuxuanchen1997
pushed a commit
that referenced
this pull request
Jul 25, 2024
Summary: Implements: https://wg21.link/LWG4035 - https://eel.is/c++draft/range.single.view Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251537
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements: https://wg21.link/LWG4035