Skip to content

Commit f4e3226

Browse files
author
Xiaoyang Liu
authored
[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.
1 parent b8e1ff3 commit f4e3226

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

libcxx/docs/Status/Cxx23Issues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"`3677 <https://wg21.link/LWG3677>`__","Is a cv-qualified ``pair`` specially handled in uses-allocator construction?", "November 2022","|Complete|","18.0",""
202202
"`3717 <https://wg21.link/LWG3717>`__","``common_view::end`` should improve ``random_access_range`` case", "November 2022","","","|ranges|"
203203
"`3732 <https://wg21.link/LWG3732>`__","``prepend_range`` and ``append_range`` can't be amortized constant time", "November 2022","|Nothing to do|","","|ranges|"
204-
"`3736 <https://wg21.link/LWG3736>`__","``move_iterator`` missing ``disable_sized_sentinel_for`` specialization", "November 2022","","","|ranges|"
204+
"`3736 <https://wg21.link/LWG3736>`__","``move_iterator`` missing ``disable_sized_sentinel_for`` specialization", "November 2022","|Complete|","19.0","|ranges|"
205205
"`3737 <https://wg21.link/LWG3737>`__","``take_view::sentinel`` should provide ``operator-``", "November 2022","","","|ranges|"
206206
"`3738 <https://wg21.link/LWG3738>`__","Missing preconditions for ``take_view`` constructor", "November 2022","|Complete|","16.0","|ranges|"
207207
"`3743 <https://wg21.link/LWG3743>`__","``ranges::to``'s reserve may be ill-formed", "November 2022","","","|ranges|"

libcxx/include/__iterator/move_iterator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterato
330330
}
331331
#endif // _LIBCPP_STD_VER >= 20
332332

333+
#if _LIBCPP_STD_VER >= 20
334+
template <class _Iter1, class _Iter2>
335+
requires(!sized_sentinel_for<_Iter1, _Iter2>)
336+
inline constexpr bool disable_sized_sentinel_for<move_iterator<_Iter1>, move_iterator<_Iter2>> = true;
337+
#endif // _LIBCPP_STD_VER >= 20
338+
333339
template <class _Iter>
334340
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 move_iterator<_Iter> make_move_iterator(_Iter __i) {
335341
return move_iterator<_Iter>(std::move(__i));

libcxx/include/iterator

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ constexpr move_iterator<Iterator> operator+( // constexpr in C++17
475475
template <class Iterator> // constexpr in C++17
476476
constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
477477
478+
template<class Iterator1, class Iterator2>
479+
requires (!sized_sentinel_for<Iterator1, Iterator2>)
480+
inline constexpr bool disable_sized_sentinel_for<move_iterator<Iterator1>, // since C++20
481+
move_iterator<Iterator2>> = true;
482+
478483
template<semiregular S>
479484
class move_sentinel {
480485
public:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// UNSUPPORTED: c++03, c++11, c++14, c++17
10+
11+
#include <iterator>
12+
13+
#include "test_iterators.h"
14+
15+
using sized_it = random_access_iterator<int*>;
16+
static_assert(std::sized_sentinel_for<sized_it, sized_it>);
17+
static_assert(std::sized_sentinel_for<std::move_iterator<sized_it>, std::move_iterator<sized_it>>);
18+
19+
struct unsized_it {
20+
using value_type = int;
21+
using difference_type = std::ptrdiff_t;
22+
23+
value_type& operator*() const;
24+
bool operator==(const unsized_it&) const;
25+
difference_type operator-(const unsized_it&) const { return 0; }
26+
};
27+
28+
template <>
29+
inline constexpr bool std::disable_sized_sentinel_for<unsized_it, unsized_it> = true;
30+
31+
static_assert(!std::sized_sentinel_for<unsized_it, unsized_it>);
32+
static_assert(!std::sized_sentinel_for<std::move_iterator<unsized_it>, std::move_iterator<unsized_it>>);

0 commit comments

Comments
 (0)