Skip to content

[libc++][ranges] LWG3736: move_iterator missing disable_sized_sentinel_for specialization #85611

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

Merged
merged 8 commits into from
Apr 12, 2024

Conversation

xiaoyang-sde
Copy link
Member

Abstract

This pull request implements LWG3736: move_iterator missing disable_sized_sentinel_for specialization. Here is an example similar to those described in the report, where unsized_it doesn't model sized_sentinel_for<unsized_it>:

#include <iterator>

struct unsized_it {
  using value_type      = int;
  using difference_type = std::ptrdiff_t;

  value_type& operator*() const;
  bool operator==(const unsized_it&) const;
  difference_type operator-(const unsized_it&) const { return 0; }
};

template <>
inline constexpr bool std::disable_sized_sentinel_for<unsized_it, unsized_it> = true;

static_assert(!std::sized_sentinel_for<unsized_it, unsized_it>);
static_assert(!std::sized_sentinel_for<std::move_iterator<unsized_it>, std::move_iterator<unsized_it>>);

Reference

@xiaoyang-sde xiaoyang-sde requested a review from a team as a code owner March 18, 2024 07:54
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2024

@llvm/pr-subscribers-libcxx

Author: Xiaoyang Liu (xiaoyang-sde)

Changes

Abstract

This pull request implements LWG3736: move_iterator missing disable_sized_sentinel_for specialization. Here is an example similar to those described in the report, where unsized_it doesn't model sized_sentinel_for&lt;unsized_it&gt;:

#include &lt;iterator&gt;

struct unsized_it {
  using value_type      = int;
  using difference_type = std::ptrdiff_t;

  value_type&amp; operator*() const;
  bool operator==(const unsized_it&amp;) const;
  difference_type operator-(const unsized_it&amp;) const { return 0; }
};

template &lt;&gt;
inline constexpr bool std::disable_sized_sentinel_for&lt;unsized_it, unsized_it&gt; = true;

static_assert(!std::sized_sentinel_for&lt;unsized_it, unsized_it&gt;);
static_assert(!std::sized_sentinel_for&lt;std::move_iterator&lt;unsized_it&gt;, std::move_iterator&lt;unsized_it&gt;&gt;);

Reference


Full diff: https://github.com/llvm/llvm-project/pull/85611.diff

4 Files Affected:

  • (modified) libcxx/docs/Status/Cxx23Issues.csv (+1-1)
  • (modified) libcxx/include/__iterator/move_iterator.h (+6)
  • (modified) libcxx/include/iterator (+5)
  • (added) libcxx/test/std/iterators/predef.iterators/move.iterators/sized_sentinel.compile.pass.cpp (+26)
diff --git a/libcxx/docs/Status/Cxx23Issues.csv b/libcxx/docs/Status/Cxx23Issues.csv
index 43282f357150cf..0625dfe3a1d853 100644
--- a/libcxx/docs/Status/Cxx23Issues.csv
+++ b/libcxx/docs/Status/Cxx23Issues.csv
@@ -201,7 +201,7 @@
 "`3677 <https://wg21.link/LWG3677>`__","Is a cv-qualified ``pair`` specially handled in uses-allocator construction?", "November 2022","|Complete|","18.0",""
 "`3717 <https://wg21.link/LWG3717>`__","``common_view::end`` should improve ``random_access_range`` case", "November 2022","","","|ranges|"
 "`3732 <https://wg21.link/LWG3732>`__","``prepend_range`` and ``append_range`` can't be amortized constant time", "November 2022","|Nothing to do|","","|ranges|"
-"`3736 <https://wg21.link/LWG3736>`__","``move_iterator`` missing ``disable_sized_sentinel_for`` specialization", "November 2022","","","|ranges|"
+"`3736 <https://wg21.link/LWG3736>`__","``move_iterator`` missing ``disable_sized_sentinel_for`` specialization", "November 2022","|Complete|","19.0","|ranges|"
 "`3737 <https://wg21.link/LWG3737>`__","``take_view::sentinel`` should provide ``operator-``", "November 2022","","","|ranges|"
 "`3738 <https://wg21.link/LWG3738>`__","Missing preconditions for ``take_view`` constructor", "November 2022","|Complete|","16.0","|ranges|"
 "`3743 <https://wg21.link/LWG3743>`__","``ranges::to``'s reserve may be ill-formed", "November 2022","","","|ranges|"
diff --git a/libcxx/include/__iterator/move_iterator.h b/libcxx/include/__iterator/move_iterator.h
index eefd5b37484548..6382c947060bfe 100644
--- a/libcxx/include/__iterator/move_iterator.h
+++ b/libcxx/include/__iterator/move_iterator.h
@@ -330,6 +330,12 @@ operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterato
 }
 #endif // _LIBCPP_STD_VER >= 20
 
+#if _LIBCPP_STD_VER >= 20
+template <class _Iter1, class _Iter2>
+  requires(!sized_sentinel_for<_Iter1, _Iter2>)
+inline constexpr bool disable_sized_sentinel_for<move_iterator<_Iter1>, move_iterator<_Iter2>> = true;
+#endif // _LIBCPP_STD_VER >= 20
+
 template <class _Iter>
 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator<_Iter> make_move_iterator(_Iter __i) {
   return move_iterator<_Iter>(std::move(__i));
diff --git a/libcxx/include/iterator b/libcxx/include/iterator
index 5779bf828711b8..40ac6d18bc1d37 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -475,6 +475,11 @@ constexpr move_iterator<Iterator> operator+(   // constexpr in C++17
 template <class Iterator>   // constexpr in C++17
 constexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
 
+template<class Iterator1, class Iterator2>
+    requires (!sized_sentinel_for<Iterator1, Iterator2>)
+  inline constexpr bool disable_sized_sentinel_for<move_iterator<Iterator1>,
+                                                    move_iterator<Iterator2>> = true;
+
 template<semiregular S>
 class move_sentinel {
 public:
diff --git a/libcxx/test/std/iterators/predef.iterators/move.iterators/sized_sentinel.compile.pass.cpp b/libcxx/test/std/iterators/predef.iterators/move.iterators/sized_sentinel.compile.pass.cpp
new file mode 100644
index 00000000000000..b2593d395d0fad
--- /dev/null
+++ b/libcxx/test/std/iterators/predef.iterators/move.iterators/sized_sentinel.compile.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+#include <iterator>
+
+struct unsized_it {
+  using value_type      = int;
+  using difference_type = std::ptrdiff_t;
+
+  value_type& operator*() const;
+  bool operator==(const unsized_it&) const;
+  difference_type operator-(const unsized_it&) const { return 0; }
+};
+
+template <>
+inline constexpr bool std::disable_sized_sentinel_for<unsized_it, unsized_it> = true;
+
+static_assert(!std::sized_sentinel_for<unsized_it, unsized_it>);
+static_assert(!std::sized_sentinel_for<std::move_iterator<unsized_it>, std::move_iterator<unsized_it>>);

@xiaoyang-sde xiaoyang-sde changed the title [libc++] [ranges] LWG3736: move_iterator missing disable_sized_sentinel_for specialization [libc++][ranges] LWG3736: move_iterator missing disable_sized_sentinel_for specialization Mar 19, 2024
@ldionne ldionne self-assigned this Mar 20, 2024
@ldionne ldionne added the ranges Issues related to `<ranges>` label Mar 20, 2024
Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This basically LGTM with a minor comment to improve testing. Thanks a lot for the patch!

Xiaoyang Liu and others added 2 commits March 19, 2024 23:58
Copy link
Member

@var-const var-const left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@xiaoyang-sde
Copy link
Member Author

Thanks!

Thanks for approving this pull request! Would you mind merging it? (I don't have the permission to do so.)

@var-const
Copy link
Member

@xiaoyang-sde Sorry, I have a last-minute comment. Other than that, LGTM, happy to merge as soon as the comment is resolved (one way or another).

@xiaoyang-sde xiaoyang-sde requested a review from var-const April 6, 2024 01:39
@ldionne
Copy link
Member

ldionne commented Apr 11, 2024

LGTM once the CI is green. Whoever sees this first can merge once green. Thanks!

@ldionne ldionne merged commit f4e3226 into llvm:main Apr 12, 2024
Copy link

@xiaoyang-sde Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@xiaoyang-sde xiaoyang-sde deleted the move_iterator branch April 12, 2024 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants