Skip to content

Commit 45c4124

Browse files
H-G-HristovZingamfrederick-vs-ja
authored
[libc++][ranges] P3060R3: Add std::views::indices(n) (#146823)
Implements [P3060R3](https://wg21.link/P3060R3) Closes #148175 # References - cplusplus/draft#7966 - cplusplus/draft#8006 - https://wg21.link/customization.point.object - https://wg21.link/range.iota.overview - https://wg21.link/ranges.syn --------- Co-authored-by: Hristo Hristov <[email protected]> Co-authored-by: A. Jiang <[email protected]>
1 parent 23e35bd commit 45c4124

File tree

12 files changed

+182
-1
lines changed

12 files changed

+182
-1
lines changed

libcxx/docs/FeatureTestMacroTable.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ Status
488488
---------------------------------------------------------- -----------------
489489
``__cpp_lib_ranges_concat`` *unimplemented*
490490
---------------------------------------------------------- -----------------
491+
``__cpp_lib_ranges_indices`` ``202506L``
492+
---------------------------------------------------------- -----------------
491493
``__cpp_lib_ratio`` ``202306L``
492494
---------------------------------------------------------- -----------------
493495
``__cpp_lib_rcu`` *unimplemented*

libcxx/docs/ReleaseNotes/22.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Implemented Papers
4242
is implemented in this release)
4343
- P3044R2: sub-``string_view`` from ``string`` (`Github <https://llvm.org/PR148140>`__)
4444
- P3223R2: Making ``std::istream::ignore`` less surprising (`Github <https://llvm.org/PR148178>`__)
45+
- P3060R3: Add ``std::views::indices(n)`` (`Github <https://llvm.org/PR148175>`__)
4546
- P3168R2: Give ``std::optional`` Range Support (`Github <https://llvm.org/PR105430>`__)
4647

4748
Improvements and New Features

libcxx/docs/Status/Cxx2cPapers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
"`P3503R3 <https://wg21.link/P3503R3>`__","Make type-erased allocator use in ``promise`` and ``packaged_task`` consistent","2025-06 (Sofia)","","","`#148164 <https://github.com/llvm/llvm-project/issues/148164>`__",""
150150
"`P3008R6 <https://wg21.link/P3008R6>`__","Atomic floating-point min/max","2025-06 (Sofia)","","","`#148168 <https://github.com/llvm/llvm-project/issues/148168>`__",""
151151
"`P3111R8 <https://wg21.link/P3111R8>`__","Atomic Reduction Operations","2025-06 (Sofia)","","","`#148174 <https://github.com/llvm/llvm-project/issues/148174>`__",""
152-
"`P3060R3 <https://wg21.link/P3060R3>`__","Add ``std::views::indices(n)``","2025-06 (Sofia)","","","`#148175 <https://github.com/llvm/llvm-project/issues/148175>`__",""
152+
"`P3060R3 <https://wg21.link/P3060R3>`__","Add ``std::views::indices(n)``","2025-06 (Sofia)","|Complete|","22","`#148175 <https://github.com/llvm/llvm-project/issues/148175>`__",""
153153
"`P2319R5 <https://wg21.link/P2319R5>`__","Prevent ``path`` presentation problems","2025-06 (Sofia)","","","`#148177 <https://github.com/llvm/llvm-project/issues/148177>`__",""
154154
"`P3223R2 <https://wg21.link/P3223R2>`__","Making ``std::istream::ignore`` less surprising","2025-06 (Sofia)","|Complete|","22","`#148178 <https://github.com/llvm/llvm-project/issues/148178>`__",""
155155
"`P2781R9 <https://wg21.link/P2781R9>`__","``std::constant_wrapper``","2025-06 (Sofia)","","","`#148179 <https://github.com/llvm/llvm-project/issues/148179>`__",""

libcxx/include/__ranges/iota_view.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,15 @@ struct __fn {
393393
inline namespace __cpo {
394394
inline constexpr auto iota = __iota::__fn{};
395395
} // namespace __cpo
396+
397+
# if _LIBCPP_STD_VER >= 26
398+
399+
inline constexpr auto indices = [](__integer_like auto __size) static {
400+
return ranges::views::iota(decltype(__size){}, __size);
401+
};
402+
403+
# endif
404+
396405
} // namespace views
397406
} // namespace ranges
398407

libcxx/include/ranges

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ namespace std::ranges {
267267
template<class W, class Bound>
268268
inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
269269
270+
namespace views {
271+
inline constexpr unspecified iota = unspecified;
272+
inline constexpr unspecified indices = unspecified; // Since C++26
273+
}
274+
270275
// [range.repeat], repeat view
271276
template<class T>
272277
concept integer-like-with-usable-difference-type = // exposition only

libcxx/include/version

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ __cpp_lib_ranges_chunk_by 202202L <ranges>
205205
__cpp_lib_ranges_concat 202403L <ranges>
206206
__cpp_lib_ranges_contains 202207L <algorithm>
207207
__cpp_lib_ranges_find_last 202207L <algorithm>
208+
__cpp_lib_ranges_indices 202506L <ranges>
208209
__cpp_lib_ranges_iota 202202L <numeric>
209210
__cpp_lib_ranges_join_with 202202L <ranges>
210211
__cpp_lib_ranges_repeat 202207L <ranges>
@@ -591,6 +592,7 @@ __cpp_lib_void_t 201411L <type_traits>
591592
# define __cpp_lib_out_ptr 202311L
592593
// # define __cpp_lib_philox_engine 202406L
593594
// # define __cpp_lib_ranges_concat 202403L
595+
# define __cpp_lib_ranges_indices 202506L
594596
# define __cpp_lib_ratio 202306L
595597
// # define __cpp_lib_rcu 202306L
596598
# define __cpp_lib_reference_wrapper 202403L

libcxx/modules/std/ranges.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ export namespace std {
114114

115115
namespace views {
116116
using std::ranges::views::iota;
117+
#if _LIBCPP_STD_VER >= 26
118+
using std::ranges::views::indices;
119+
#endif
117120
} // namespace views
118121

119122
#if _LIBCPP_STD_VER >= 23

libcxx/test/std/language.support/support.limits/support.limits.general/ranges.version.compile.pass.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
# error "__cpp_lib_ranges_concat should not be defined before c++26"
4949
# endif
5050

51+
# ifdef __cpp_lib_ranges_indices
52+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
53+
# endif
54+
5155
# ifdef __cpp_lib_ranges_join_with
5256
# error "__cpp_lib_ranges_join_with should not be defined before c++23"
5357
# endif
@@ -98,6 +102,10 @@
98102
# error "__cpp_lib_ranges_concat should not be defined before c++26"
99103
# endif
100104

105+
# ifdef __cpp_lib_ranges_indices
106+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
107+
# endif
108+
101109
# ifdef __cpp_lib_ranges_join_with
102110
# error "__cpp_lib_ranges_join_with should not be defined before c++23"
103111
# endif
@@ -148,6 +156,10 @@
148156
# error "__cpp_lib_ranges_concat should not be defined before c++26"
149157
# endif
150158

159+
# ifdef __cpp_lib_ranges_indices
160+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
161+
# endif
162+
151163
# ifdef __cpp_lib_ranges_join_with
152164
# error "__cpp_lib_ranges_join_with should not be defined before c++23"
153165
# endif
@@ -201,6 +213,10 @@
201213
# error "__cpp_lib_ranges_concat should not be defined before c++26"
202214
# endif
203215

216+
# ifdef __cpp_lib_ranges_indices
217+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
218+
# endif
219+
204220
# ifdef __cpp_lib_ranges_join_with
205221
# error "__cpp_lib_ranges_join_with should not be defined before c++23"
206222
# endif
@@ -278,6 +294,10 @@
278294
# error "__cpp_lib_ranges_concat should not be defined before c++26"
279295
# endif
280296

297+
# ifdef __cpp_lib_ranges_indices
298+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
299+
# endif
300+
281301
# ifndef __cpp_lib_ranges_join_with
282302
# error "__cpp_lib_ranges_join_with should be defined in c++23"
283303
# endif
@@ -400,6 +420,13 @@
400420
# endif
401421
# endif
402422

423+
# ifndef __cpp_lib_ranges_indices
424+
# error "__cpp_lib_ranges_indices should be defined in c++26"
425+
# endif
426+
# if __cpp_lib_ranges_indices != 202506L
427+
# error "__cpp_lib_ranges_indices should have the value 202506L in c++26"
428+
# endif
429+
403430
# ifndef __cpp_lib_ranges_join_with
404431
# error "__cpp_lib_ranges_join_with should be defined in c++26"
405432
# endif

libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,10 @@
664664
# error "__cpp_lib_ranges_find_last should not be defined before c++23"
665665
# endif
666666

667+
# ifdef __cpp_lib_ranges_indices
668+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
669+
# endif
670+
667671
# ifdef __cpp_lib_ranges_iota
668672
# error "__cpp_lib_ranges_iota should not be defined before c++23"
669673
# endif
@@ -1608,6 +1612,10 @@
16081612
# error "__cpp_lib_ranges_find_last should not be defined before c++23"
16091613
# endif
16101614

1615+
# ifdef __cpp_lib_ranges_indices
1616+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
1617+
# endif
1618+
16111619
# ifdef __cpp_lib_ranges_iota
16121620
# error "__cpp_lib_ranges_iota should not be defined before c++23"
16131621
# endif
@@ -2723,6 +2731,10 @@
27232731
# error "__cpp_lib_ranges_find_last should not be defined before c++23"
27242732
# endif
27252733

2734+
# ifdef __cpp_lib_ranges_indices
2735+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
2736+
# endif
2737+
27262738
# ifdef __cpp_lib_ranges_iota
27272739
# error "__cpp_lib_ranges_iota should not be defined before c++23"
27282740
# endif
@@ -4111,6 +4123,10 @@
41114123
# error "__cpp_lib_ranges_find_last should not be defined before c++23"
41124124
# endif
41134125

4126+
# ifdef __cpp_lib_ranges_indices
4127+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
4128+
# endif
4129+
41144130
# ifdef __cpp_lib_ranges_iota
41154131
# error "__cpp_lib_ranges_iota should not be defined before c++23"
41164132
# endif
@@ -5694,6 +5710,10 @@
56945710
# error "__cpp_lib_ranges_find_last should have the value 202207L in c++23"
56955711
# endif
56965712

5713+
# ifdef __cpp_lib_ranges_indices
5714+
# error "__cpp_lib_ranges_indices should not be defined before c++26"
5715+
# endif
5716+
56975717
# ifndef __cpp_lib_ranges_iota
56985718
# error "__cpp_lib_ranges_iota should be defined in c++23"
56995719
# endif
@@ -7610,6 +7630,13 @@
76107630
# error "__cpp_lib_ranges_find_last should have the value 202207L in c++26"
76117631
# endif
76127632

7633+
# ifndef __cpp_lib_ranges_indices
7634+
# error "__cpp_lib_ranges_indices should be defined in c++26"
7635+
# endif
7636+
# if __cpp_lib_ranges_indices != 202506L
7637+
# error "__cpp_lib_ranges_indices should have the value 202506L in c++26"
7638+
# endif
7639+
76137640
# ifndef __cpp_lib_ranges_iota
76147641
# error "__cpp_lib_ranges_iota should be defined in c++26"
76157642
# endif

libcxx/test/std/library/description/conventions/customization.point.object/cpo.compile.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ static_assert(test(std::ranges::ssize, a));
8989
// views::empty<T> is not a CPO
9090
static_assert(test(std::views::iota, 1));
9191
static_assert(test(std::views::iota, 1, 10));
92+
#if TEST_STD_VER >= 26
93+
static_assert(test(std::views::indices, 10));
94+
#endif
9295
#ifndef TEST_HAS_NO_LOCALIZATION
9396
static_assert(test(std::views::istream<int>, stream));
9497
#endif

0 commit comments

Comments
 (0)