[libcxx-commits] [libcxx] [libc++][ranges] LWG3736: `move_iterator` missing `disable_sized_sentinel_for` specialization (PR #85611)
Xiaoyang Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 5 17:01:10 PDT 2024
https://github.com/xiaoyang-sde updated https://github.com/llvm/llvm-project/pull/85611
>From b2617a4ade71d8296535c8d74d6b281e85ac2bce Mon Sep 17 00:00:00 2001
From: Xiaoyang Liu <siujoeng.lau at gmail.com>
Date: Mon, 18 Mar 2024 00:08:30 -0700
Subject: [PATCH 1/6] [libc++] [ranges] LWG3736: 'move_iterator' missing
'disable_sized_sentinel_for' specialization
---
libcxx/docs/Status/Cxx23Issues.csv | 2 +-
libcxx/include/__iterator/move_iterator.h | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
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));
>From af6c27af64534dfcf5d0c166c34ad3f0b57bbd6b Mon Sep 17 00:00:00 2001
From: Xiaoyang Liu <siujoeng.lau at gmail.com>
Date: Mon, 18 Mar 2024 00:48:08 -0700
Subject: [PATCH 2/6] [libc++] [ranges] implement
'sized_sentinel.compile.pass.cpp'
---
.../sized_sentinel.compile.pass.cpp | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
create mode 100644 libcxx/test/std/iterators/predef.iterators/move.iterators/sized_sentinel.compile.pass.cpp
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>>);
>From 90da6abf936c8366686ae87d5c5c869ead602bba Mon Sep 17 00:00:00 2001
From: Xiaoyang Liu <siujoeng.lau at gmail.com>
Date: Mon, 18 Mar 2024 00:53:39 -0700
Subject: [PATCH 3/6] [libc++] [ranges] update 'iterator' synopsis
---
libcxx/include/iterator | 5 +++++
1 file changed, 5 insertions(+)
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:
>From 42ea56ce8c576fd574f5665d60d652d5c00888b8 Mon Sep 17 00:00:00 2001
From: Xiaoyang Liu <siujoeng.lau at gmail.com>
Date: Tue, 19 Mar 2024 23:58:55 -0700
Subject: [PATCH 4/6] [libc++][ranges] LWG3736: 'move_iterator' missing
'disable_sized_sentinel_for' specialization
Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>
---
libcxx/include/iterator | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/iterator b/libcxx/include/iterator
index 40ac6d18bc1d37..1b9e7eaf0c1e8c 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -477,7 +477,7 @@ 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>,
+ inline constexpr bool disable_sized_sentinel_for<move_iterator<Iterator1>, // since C++20
move_iterator<Iterator2>> = true;
template<semiregular S>
>From 62f348e13fcadda55f25a7cb89e03b7120727af7 Mon Sep 17 00:00:00 2001
From: Xiaoyang Liu <siujoeng.lau at gmail.com>
Date: Wed, 20 Mar 2024 00:03:12 -0700
Subject: [PATCH 5/6] [libc++][ranges] LWG3736: 'move_iterator' missing
'disable_sized_sentinel_for' specialization
---
.../move.iterators/sized_sentinel.compile.pass.cpp | 6 ++++++
1 file changed, 6 insertions(+)
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
index b2593d395d0fad..cb49086dd6802b 100644
--- 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
@@ -10,6 +10,12 @@
#include <iterator>
+#include "test_iterators.h"
+
+using sized_it = random_access_iterator<int*>;
+static_assert(std::sized_sentinel_for<sized_it, sized_it>);
+static_assert(std::sized_sentinel_for<std::move_iterator<sized_it>, std::move_iterator<sized_it>>);
+
struct unsized_it {
using value_type = int;
using difference_type = std::ptrdiff_t;
>From aad349c80939e52a6e6c3a149b73181bbf4f3774 Mon Sep 17 00:00:00 2001
From: Xiaoyang Liu <siujoeng.lau at gmail.com>
Date: Fri, 5 Apr 2024 17:00:58 -0700
Subject: [PATCH 6/6] [libc++][ranges] LWG3736: 'move_iterator' missing
'disable_sized_sentinel_for' specialization
---
libcxx/include/iterator | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libcxx/include/iterator b/libcxx/include/iterator
index 1b9e7eaf0c1e8c..3c4d09511107e8 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -477,7 +477,7 @@ 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>, // since C++20
+ inline constexpr bool disable_sized_sentinel_for<move_iterator<Iterator1>, // since C++23
move_iterator<Iterator2>> = true;
template<semiregular S>
More information about the libcxx-commits
mailing list