[libcxx-commits] [libcxx] f4e3226 - [libc++][ranges] LWG3736: move_iterator missing disable_sized_sentinel_for specialization (#85611)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Apr 12 07:09:09 PDT 2024
Author: Xiaoyang Liu
Date: 2024-04-12T10:09:05-04:00
New Revision: f4e3226a6c2bd89247192e4aae395a8deb3868b1
URL: https://github.com/llvm/llvm-project/commit/f4e3226a6c2bd89247192e4aae395a8deb3868b1
DIFF: https://github.com/llvm/llvm-project/commit/f4e3226a6c2bd89247192e4aae395a8deb3868b1.diff
LOG: [libc++][ranges] LWG3736: move_iterator missing disable_sized_sentinel_for specialization (#85611)
This pull request implements LWG3736: move_iterator missing
disable_sized_sentinel_for specialization.
Added:
libcxx/test/std/iterators/predef.iterators/move.iterators/sized_sentinel.compile.pass.cpp
Modified:
libcxx/docs/Status/Cxx23Issues.csv
libcxx/include/__iterator/move_iterator.h
libcxx/include/iterator
Removed:
################################################################################
diff --git a/libcxx/docs/Status/Cxx23Issues.csv b/libcxx/docs/Status/Cxx23Issues.csv
index fa82e67ac7db71..04f6e23375acdf 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>::
diff erence_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..1b9e7eaf0c1e8c 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>, // since C++20
+ 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..cb49086dd6802b
--- /dev/null
+++ b/libcxx/test/std/iterators/predef.iterators/move.iterators/sized_sentinel.compile.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+#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
diff erence_type = std::ptr
diff _t;
+
+ value_type& operator*() const;
+ bool operator==(const unsized_it&) const;
+
diff erence_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>>);
More information about the libcxx-commits
mailing list