forked from cplusplus/draft
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ranges.tex
17733 lines (14909 loc) · 591 KB
/
ranges.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%!TEX root = std.tex
\rSec0[ranges]{Ranges library}
\rSec1[ranges.general]{General}
\pnum
This Clause describes components for dealing with ranges of elements.
\pnum
The following subclauses describe
range and view requirements, and
components for
range primitives and range generators
as summarized in \tref{range.summary}.
\begin{libsumtab}{Ranges library summary}{range.summary}
\ref{range.access} & Range access & \tcode{<ranges>} \\
\ref{range.req} & Requirements & \\
\ref{range.utility} & Range utilities & \\
\ref{range.factories} & Range factories & \\
\ref{range.adaptors} & Range adaptors & \\ \rowsep
\ref{coro.generator} & Range generators & \libheader{generator} \\
\end{libsumtab}
\rSec1[ranges.syn]{Header \tcode{<ranges>} synopsis}
\indexheader{ranges}%
\indexlibraryglobal{all_t}%
\begin{codeblock}
#include <compare> // see \ref{compare.syn}
#include <initializer_list> // see \ref{initializer.list.syn}
#include <iterator> // see \ref{iterator.synopsis}
namespace std::ranges {
inline namespace @\unspec@ {
// \ref{range.access}, range access
inline constexpr @\unspec@ begin = @\unspec@; // freestanding
inline constexpr @\unspec@ end = @\unspec@; // freestanding
inline constexpr @\unspec@ cbegin = @\unspec@; // freestanding
inline constexpr @\unspec@ cend = @\unspec@; // freestanding
inline constexpr @\unspec@ rbegin = @\unspec@; // freestanding
inline constexpr @\unspec@ rend = @\unspec@; // freestanding
inline constexpr @\unspec@ crbegin = @\unspec@; // freestanding
inline constexpr @\unspec@ crend = @\unspec@; // freestanding
inline constexpr @\unspec@ size = @\unspec@; // freestanding
inline constexpr @\unspec@ ssize = @\unspec@; // freestanding
inline constexpr @\unspec@ empty = @\unspec@; // freestanding
inline constexpr @\unspec@ data = @\unspec@; // freestanding
inline constexpr @\unspec@ cdata = @\unspec@; // freestanding
}
// \ref{range.range}, ranges
template<class T>
concept range = @\seebelow@; // freestanding
template<class T>
constexpr bool enable_borrowed_range = false; // freestanding
template<class T>
concept borrowed_range = @\seebelow@; // freestanding
template<class T>
using iterator_t = decltype(ranges::begin(declval<T&>())); // freestanding
template<@\libconcept{range}@ R>
using sentinel_t = decltype(ranges::end(declval<R&>())); // freestanding
template<@\libconcept{range}@ R>
using const_iterator_t = decltype(ranges::cbegin(declval<R&>())); // freestanding
template<@\libconcept{range}@ R>
using const_sentinel_t = decltype(ranges::cend(declval<R&>())); // freestanding
template<@\libconcept{range}@ R>
using range_difference_t = iter_difference_t<iterator_t<R>>; // freestanding
template<@\libconcept{sized_range}@ R>
using range_size_t = decltype(ranges::size(declval<R&>())); // freestanding
template<@\libconcept{range}@ R>
using range_value_t = iter_value_t<iterator_t<R>>; // freestanding
template<@\libconcept{range}@ R>
using range_reference_t = iter_reference_t<iterator_t<R>>; // freestanding
template<@\libconcept{range}@ R>
using range_const_reference_t = iter_const_reference_t<iterator_t<R>>; // freestanding
template<@\libconcept{range}@ R>
using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<R>>; // freestanding
template<@\libconcept{range}@ R>
using range_common_reference_t = iter_common_reference_t<iterator_t<R>>; // freestanding
// \ref{range.sized}, sized ranges
template<class>
constexpr bool disable_sized_range = false; // freestanding
template<class T>
concept sized_range = @\seebelow@; // freestanding
// \ref{range.view}, views
template<class T>
constexpr bool enable_view = @\seebelow@; // freestanding
struct view_base {}; // freestanding
template<class T>
concept view = @\seebelow@; // freestanding
// \ref{range.refinements}, other range refinements
template<class R, class T>
concept output_range = @\seebelow@; // freestanding
template<class T>
concept input_range = @\seebelow@; // freestanding
template<class T>
concept forward_range = @\seebelow@; // freestanding
template<class T>
concept bidirectional_range = @\seebelow@; // freestanding
template<class T>
concept random_access_range = @\seebelow@; // freestanding
template<class T>
concept contiguous_range = @\seebelow@; // freestanding
template<class T>
concept common_range = @\seebelow@; // freestanding
template<class T>
concept viewable_range = @\seebelow@; // freestanding
template<class T>
concept constant_range = @\seebelow@; // freestanding
// \ref{view.interface}, class template \tcode{view_interface}
template<class D>
requires is_class_v<D> && @\libconcept{same_as}@<D, remove_cv_t<D>>
class view_interface; // freestanding
// \ref{range.subrange}, sub-ranges
enum class @\libglobal{subrange_kind}@ : bool { @\libmember{unsized}{subrange_kind}@, @\libmember{sized}{subrange_kind}@ }; // freestanding
template<@\libconcept{input_or_output_iterator}@ I, @\libconcept{sentinel_for}@<I> S = I, subrange_kind K = @\seebelow@>
requires (K == subrange_kind::sized || !@\libconcept{sized_sentinel_for}@<S, I>)
class subrange; // freestanding
template<class I, class S, subrange_kind K>
constexpr bool @\libspec{enable_borrowed_range}{subrange}@<subrange<I, S, K>> = true; // freestanding
template<size_t N, class I, class S, subrange_kind K>
requires ((N == 0 && @\libconcept{copyable}@<I>) || N == 1)
constexpr auto get(const subrange<I, S, K>& r); // freestanding
template<size_t N, class I, class S, subrange_kind K>
requires (N < 2)
constexpr auto get(subrange<I, S, K>&& r); // freestanding
}
namespace std {
using ranges::get; // freestanding
}
namespace std::ranges {
// \ref{range.dangling}, dangling iterator handling
struct dangling; // freestanding
// \ref{range.elementsof}, class template \tcode{elements_of}
template<@\libconcept{range}@ R, class Allocator = allocator<byte>>
struct elements_of;
template<@\libconcept{range}@ R>
using borrowed_iterator_t = @\seebelow@; // freestanding
template<@\libconcept{range}@ R>
using borrowed_subrange_t = @\seebelow@; // freestanding
// \ref{range.utility.conv}, range conversions
template<class C, @\libconcept{input_range}@ R, class... Args> requires (!@\libconcept{view}@<C>)
constexpr C to(R&& r, Args&&... args); // freestanding
template<template<class...> class C, @\libconcept{input_range}@ R, class... Args>
constexpr auto to(R&& r, Args&&... args); // freestanding
template<class C, class... Args> requires (!@\libconcept{view}@<C>)
constexpr auto to(Args&&... args); // freestanding
template<template<class...> class C, class... Args>
constexpr auto to(Args&&... args); // freestanding
// \ref{range.empty}, empty view
template<class T>
requires is_object_v<T>
class empty_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{empty_view}@<empty_view<T>> = true; // freestanding
namespace views {
template<class T>
constexpr empty_view<T> @\libmember{empty}{views}@{}; // freestanding
}
// \ref{range.single}, single view
template<@\libconcept{move_constructible}@ T>
requires is_object_v<T>
class single_view; // freestanding
namespace views { inline constexpr @\unspecnc@ single = @\unspecnc@; } // freestanding
template<bool Const, class T>
using @\exposidnc{maybe-const}@ = conditional_t<Const, const T, T>; // \expos
// \ref{range.iota}, iota view
template<@\libconcept{weakly_incrementable}@ W, @\libconcept{semiregular}@ Bound = unreachable_sentinel_t>
requires @\exposconcept{weakly-equality-comparable-with}@<W, Bound> && @\libconcept{copyable}@<W>
class iota_view; // freestanding
template<class W, class Bound>
constexpr bool @\libspec{enable_borrowed_range}{iota_view}@<iota_view<W, Bound>> = true; // freestanding
namespace views { inline constexpr @\unspecnc@ iota = @\unspecnc@; } // freestanding
// \ref{range.repeat}, repeat view
template<@\libconcept{move_constructible}@ T, @\libconcept{semiregular}@ Bound = unreachable_sentinel_t>
requires @\seebelow@
class repeat_view; // freestanding
namespace views { inline constexpr @\unspecnc@ repeat = @\unspecnc@; } // freestanding
// \ref{range.istream}, istream view
template<@\libconcept{movable}@ Val, class CharT, class Traits = char_traits<CharT>>
requires @\seebelow@
class basic_istream_view;
template<class Val>
using istream_view = basic_istream_view<Val, char>;
template<class Val>
using wistream_view = basic_istream_view<Val, wchar_t>;
namespace views { template<class T> constexpr @\unspecnc@ istream = @\unspecnc@; }
// \ref{range.adaptor.object}, range adaptor objects
template<class D>
requires is_class_v<D> && @\libconcept{same_as}@<D, remove_cv_t<D>>
class range_adaptor_closure { }; // freestanding
// \ref{range.all}, all view
namespace views {
inline constexpr @\unspecnc@ all = @\unspecnc@; // freestanding
template<@\libconcept{viewable_range}@ R>
using all_t = decltype(all(declval<R>())); // freestanding
}
// \ref{range.ref.view}, ref view
template<@\libconcept{range}@ R>
requires is_object_v<R>
class ref_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{ref_view}@<ref_view<T>> = true; // freestanding
// \ref{range.owning.view}, owning view
template<@\libconcept{range}@ R>
requires @\seebelow@
class owning_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{owning_view}@<owning_view<T>> = // freestanding
enable_borrowed_range<T>;
// \ref{range.as.rvalue}, as rvalue view
template<@\libconcept{view}@ V>
requires @\libconcept{input_range}@<V>
class as_rvalue_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{as_rvalue_view}@<as_rvalue_view<T>> = // freestanding
enable_borrowed_range<T>;
namespace views { inline constexpr @\unspecnc@ as_rvalue = @\unspecnc@; } // freestanding
// \ref{range.filter}, filter view
template<@\libconcept{input_range}@ V, @\libconcept{indirect_unary_predicate}@<iterator_t<V>> Pred>
requires @\libconcept{view}@<V> && is_object_v<Pred>
class filter_view; // freestanding
namespace views { inline constexpr @\unspecnc@ filter = @\unspecnc@; } // freestanding
// \ref{range.transform}, transform view
template<@\libconcept{input_range}@ V, @\libconcept{move_constructible}@ F>
requires @\libconcept{view}@<V> && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<V>> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<V>>>
class transform_view; // freestanding
namespace views { inline constexpr @\unspecnc@ transform = @\unspecnc@; } // freestanding
// \ref{range.take}, take view
template<@\libconcept{view}@> class take_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{take_view}@<take_view<T>> = // freestanding
enable_borrowed_range<T>;
namespace views { inline constexpr @\unspecnc@ take = @\unspecnc@; } // freestanding
// \ref{range.take.while}, take while view
template<@\libconcept{view}@ V, class Pred>
requires @\libconcept{input_range}@<V> && is_object_v<Pred> &&
@\libconcept{indirect_unary_predicate}@<const Pred, iterator_t<V>>
class take_while_view; // freestanding
namespace views { inline constexpr @\unspecnc@ take_while = @\unspecnc@; } // freestanding
// \ref{range.drop}, drop view
template<@\libconcept{view}@ V>
class drop_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{drop_view}@<drop_view<T>> = // freestanding
enable_borrowed_range<T>;
namespace views { inline constexpr @\unspecnc@ drop = @\unspecnc@; } // freestanding
// \ref{range.drop.while}, drop while view
template<@\libconcept{view}@ V, class Pred>
requires @\libconcept{input_range}@<V> && is_object_v<Pred> &&
@\libconcept{indirect_unary_predicate}@<const Pred, iterator_t<V>>
class drop_while_view; // freestanding
template<class T, class Pred>
constexpr bool @\libspec{enable_borrowed_range}{drop_while_view}@<drop_while_view<T, Pred>> = // freestanding
enable_borrowed_range<T>;
namespace views { inline constexpr @\unspecnc@ drop_while = @\unspecnc@; } // freestanding
// \ref{range.join}, join view
template<@\libconcept{input_range}@ V>
requires @\libconcept{view}@<V> && @\libconcept{input_range}@<range_reference_t<V>>
class join_view; // freestanding
namespace views { inline constexpr @\unspecnc@ join = @\unspecnc@; } // freestanding
// \ref{range.join.with}, join with view
template<@\libconcept{input_range}@ V, @\libconcept{forward_range}@ Pattern>
requires @\seebelow@
class join_with_view; // freestanding
namespace views { inline constexpr @\unspecnc@ join_with = @\unspecnc@; } // freestanding
// \ref{range.lazy.split}, lazy split view
template<class R>
concept @\exposconcept{tiny-range}@ = @\seebelow@; // \expos
template<@\libconcept{input_range}@ V, @\libconcept{forward_range}@ Pattern>
requires @\libconcept{view}@<V> && @\libconcept{view}@<Pattern> &&
@\libconcept{indirectly_comparable}@<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
(@\libconcept{forward_range}@<V> || @\exposconcept{tiny-range}@<Pattern>)
class lazy_split_view; // freestanding
// \ref{range.split}, split view
template<@\libconcept{forward_range}@ V, @\libconcept{forward_range}@ Pattern>
requires @\libconcept{view}@<V> && @\libconcept{view}@<Pattern> &&
@\libconcept{indirectly_comparable}@<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to>
class split_view; // freestanding
namespace views {
inline constexpr @\unspecnc@ lazy_split = @\unspecnc@; // freestanding
inline constexpr @\unspecnc@ split = @\unspecnc@; // freestanding
}
// \ref{range.concat}, concat view
template<@\libconcept{input_range}@... Views>
requires @\seebelow@
class concat_view; // freestanding
namespace views { inline constexpr @\unspecnc@ concat = @\unspecnc@; } // freestanding
// \ref{range.counted}, counted view
namespace views { inline constexpr @\unspecnc@ counted = @\unspecnc@; } // freestanding
// \ref{range.common}, common view
template<@\libconcept{view}@ V>
requires (!@\libconcept{common_range}@<V> && @\libconcept{copyable}@<iterator_t<V>>)
class common_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{common_view}@<common_view<T>> = // freestanding
enable_borrowed_range<T>;
namespace views { inline constexpr @\unspecnc@ common = @\unspecnc@; } // freestanding
// \ref{range.reverse}, reverse view
template<@\libconcept{view}@ V>
requires @\libconcept{bidirectional_range}@<V>
class reverse_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{reverse_view}@<reverse_view<T>> = // freestanding
enable_borrowed_range<T>;
namespace views { inline constexpr @\unspecnc@ reverse = @\unspecnc@; } // freestanding
// \ref{range.as.const}, as const view
template<@\libconcept{input_range}@ R>
constexpr auto& @\exposid{possibly-const-range}@(R& r) noexcept { // \expos
if constexpr (@\libconcept{input_range}@<const R>) {
return const_cast<const R&>(r);
} else {
return r;
}
}
template<@\libconcept{view}@ V>
requires @\libconcept{input_range}@<V>
class as_const_view; // freestanding
template<class T>
constexpr bool @\libspec{enable_borrowed_range}{as_const_view}@<as_const_view<T>> = // freestanding
enable_borrowed_range<T>;
namespace views { inline constexpr @\unspecnc@ as_const = @\unspecnc@; } // freestanding
// \ref{range.elements}, elements view
template<@\libconcept{input_range}@ V, size_t N>
requires @\seebelow@
class elements_view; // freestanding
template<class T, size_t N>
constexpr bool @\libspec{enable_borrowed_range}{elements_view}@<elements_view<T, N>> = // freestanding
enable_borrowed_range<T>;
template<class R>
using @\libglobal{keys_view}@ = elements_view<R, 0>; // freestanding
template<class R>
using @\libglobal{values_view}@ = elements_view<R, 1>; // freestanding
namespace views {
template<size_t N>
constexpr @\unspecnc@ elements = @\unspecnc@; // freestanding
inline constexpr auto @\libmember{keys}{views}@ = elements<0>; // freestanding
inline constexpr auto @\libmember{values}{views}@ = elements<1>; // freestanding
}
// \ref{range.enumerate}, enumerate view
template<@\libconcept{view}@ V>
requires @\seebelow@
class enumerate_view; // freestanding
template<class View>
constexpr bool @\libspec{enable_borrowed_range}{enumerate_view}@<enumerate_view<View>> = // freestanding
enable_borrowed_range<View>;
namespace views { inline constexpr @\unspecnc@ enumerate = @\unspecnc@; } // freestanding
// \ref{range.zip}, zip view
template<@\libconcept{input_range}@... Views>
requires (@\libconcept{view}@<Views> && ...) && (sizeof...(Views) > 0)
class zip_view; // freestanding
template<class... Views>
constexpr bool @\libspec{enable_borrowed_range}{zip_view}@<zip_view<Views...>> = // freestanding
(enable_borrowed_range<Views> && ...);
namespace views { inline constexpr @\unspecnc@ zip = @\unspecnc@; } // freestanding
// \ref{range.zip.transform}, zip transform view
template<@\libconcept{move_constructible}@ F, @\libconcept{input_range}@... Views>
requires (@\libconcept{view}@<Views> && ...) && (sizeof...(Views) > 0) && is_object_v<F> &&
@\libconcept{regular_invocable}@<F&, range_reference_t<Views>...> &&
@\exposconcept{can-reference}@<invoke_result_t<F&, range_reference_t<Views>...>>
class zip_transform_view; // freestanding
namespace views { inline constexpr @\unspecnc@ zip_transform = @\unspecnc@; } // freestanding
// \ref{range.adjacent}, adjacent view
template<@\libconcept{forward_range}@ V, size_t N>
requires @\libconcept{view}@<V> && (N > 0)
class adjacent_view; // freestanding
template<class V, size_t N>
constexpr bool @\libspec{enable_borrowed_range}{adjacent_view}@<adjacent_view<V, N>> = // freestanding
enable_borrowed_range<V>;
namespace views {
template<size_t N>
constexpr @\unspecnc@ adjacent = @\unspecnc@; // freestanding
inline constexpr auto @\libmember{pairwise}{views}@ = adjacent<2>; // freestanding
}
// \ref{range.adjacent.transform}, adjacent transform view
template<@\libconcept{forward_range}@ V, @\libconcept{move_constructible}@ F, size_t N>
requires @\seebelow@
class adjacent_transform_view; // freestanding
namespace views {
template<size_t N>
constexpr @\unspecnc@ adjacent_transform = @\unspecnc@; // freestanding
inline constexpr auto @\libmember{pairwise_transform}{views}@ = adjacent_transform<2>; // freestanding
}
// \ref{range.chunk}, chunk view
template<@\libconcept{view}@ V>
requires @\libconcept{input_range}@<V>
class chunk_view; // freestanding
template<@\libconcept{view}@ V>
requires @\libconcept{forward_range}@<V>
class chunk_view<V>; // freestanding
template<class V>
constexpr bool @\libspec{enable_borrowed_range}{chunk_view}@<chunk_view<V>> = // freestanding
@\libconcept{forward_range}@<V> && enable_borrowed_range<V>;
namespace views { inline constexpr @\unspecnc@ chunk = @\unspecnc@; } // freestanding
// \ref{range.slide}, slide view
template<@\libconcept{forward_range}@ V>
requires @\libconcept{view}@<V>
class slide_view; // freestanding
template<class V>
constexpr bool @\libspec{enable_borrowed_range}{slide_view}@<slide_view<V>> = // freestanding
enable_borrowed_range<V>;
namespace views { inline constexpr @\unspecnc@ slide = @\unspecnc@; } // freestanding
// \ref{range.chunk.by}, chunk by view
template<@\libconcept{forward_range}@ V, @\libconcept{indirect_binary_predicate}@<iterator_t<V>, iterator_t<V>> Pred>
requires @\libconcept{view}@<V> && is_object_v<Pred>
class chunk_by_view; // freestanding
namespace views { inline constexpr @\unspecnc@ chunk_by = @\unspecnc@; } // freestanding
// \ref{range.stride}, stride view
template<@\libconcept{input_range}@ V>
requires @\libconcept{view}@<V>
class stride_view; // freestanding
template<class V>
constexpr bool @\libspec{enable_borrowed_range}{stride_view}@<stride_view<V>> = // freestanding
enable_borrowed_range<V>;
namespace views { inline constexpr @\unspecnc@ stride = @\unspecnc@; } // freestanding
// \ref{range.cartesian}, cartesian product view
template<@\libconcept{input_range}@ First, @\libconcept{forward_range}@... Vs>
requires (@\libconcept{view}@<First> && ... && @\libconcept{view}@<Vs>)
class cartesian_product_view; // freestanding
namespace views { inline constexpr @\unspecnc@ cartesian_product = @\unspecnc@; } // freestanding
// \ref{range.cache.latest}, cache latest view
template<@\libconcept{input_range}@ V>
requires @\libconcept{view}@<V>
class cache_latest_view;
namespace views { inline constexpr @\unspec@ cache_latest = @\unspec@; }
}
namespace std {
namespace views = ranges::views; // freestanding
template<class T> struct tuple_size; // freestanding
template<size_t I, class T> struct tuple_element; // freestanding
template<class I, class S, ranges::subrange_kind K>
struct tuple_size<ranges::subrange<I, S, K>> // freestanding
: integral_constant<size_t, 2> {};
template<class I, class S, ranges::subrange_kind K>
struct tuple_element<0, ranges::subrange<I, S, K>> { // freestanding
using type = I;
};
template<class I, class S, ranges::subrange_kind K>
struct tuple_element<1, ranges::subrange<I, S, K>> { // freestanding
using type = S;
};
template<class I, class S, ranges::subrange_kind K>
struct tuple_element<0, const ranges::subrange<I, S, K>> { // freestanding
using type = I;
};
template<class I, class S, ranges::subrange_kind K>
struct tuple_element<1, const ranges::subrange<I, S, K>> { // freestanding
using type = S;
};
struct from_range_t { explicit from_range_t() = default; }; // freestanding
inline constexpr from_range_t from_range{}; // freestanding
}
\end{codeblock}
\pnum
\indextext{to-unsigned-like@\exposid{to-unsigned-like}}%
\indextext{make-unsigned-like-t@\exposid{make-unsigned-like-t}}%
Within this Clause,
for an integer-like type \tcode{X}\iref{iterator.concept.winc},
\tcode{\placeholdernc{make-unsigned-like-t}<X>} denotes
\tcode{make_unsigned_t<X>} if \tcode{X} is an integer type;
otherwise, it denotes a corresponding unspecified unsigned-integer-like type
of the same width as \tcode{X}.
For an expression \tcode{x} of type \tcode{X},
\tcode{\placeholdernc{to-unsigned-like}(x)} is
\tcode{x} explicitly converted to
\tcode{\placeholdernc{make-unsigned-like-t}<X>}.
\pnum
Also within this Clause,
\tcode{\exposid{make-signed-like-t}<X>} for an integer-like type \tcode{X}
denotes \tcode{make_signed_t<X>} if \tcode{X} is an integer type;
otherwise, it denotes a corresponding unspecified signed-integer-like type
of the same width as \tcode{X}.
\rSec1[range.access]{Range access}
\rSec2[range.access.general]{General}
\pnum
In addition to being available via inclusion of the \libheader{ranges}
header, the customization point objects in \ref{range.access} are
available when the header \libheaderrefx{iterator}{iterator.synopsis} is included.
\pnum
Within \ref{range.access},
the \defnadj{reified}{object} of a subexpression \tcode{E} denotes
\begin{itemize}
\item
the same object as \tcode{E} if \tcode{E} is a glvalue, or
\item
the result of applying
the temporary materialization conversion\iref{conv.rval} to \tcode{E} otherwise.
\end{itemize}
\rSec2[range.access.begin]{\tcode{ranges::begin}}
\indexlibraryglobal{begin}%
\pnum
The name \tcode{ranges::begin} denotes a customization point
object\iref{customization.point.object}.
\pnum
Given a subexpression \tcode{E} with type \tcode{T},
let \tcode{t} be an lvalue that denotes the reified object for \tcode{E}.
Then:
\begin{itemize}
\item
If \tcode{E} is an rvalue and
\tcode{enable_borrowed_range<remove_cv_t<T>>} is \tcode{false},
\tcode{ranges::begin(E)} is ill-formed.
\item
Otherwise, if \tcode{T} is an array type\iref{term.array.type} and
\tcode{remove_all_extents_t<T>} is an incomplete type,
\tcode{ranges::begin(E)} is ill-formed with no diagnostic required.
\item
Otherwise, if \tcode{T} is an array type,
\tcode{ranges::begin(E)} is expression-equivalent to \tcode{t + 0}.
\item
Otherwise, if \tcode{auto(t.begin())}
is a valid expression whose type models
\libconcept{input_or_output_iterator},
\tcode{ranges::begin(E)} is expression-equivalent to
\tcode{auto(t.begin())}.
\item
Otherwise, if \tcode{T} is a class or enumeration type and
\tcode{auto(begin(t))}
is a valid expression whose type models
\libconcept{input_or_output_iterator}
where the meaning of \tcode{begin} is established as-if by performing
argument-dependent lookup only\iref{basic.lookup.argdep},
then \tcode{ranges::begin(E)} is expression-equivalent to
that expression.
\item
Otherwise, \tcode{ranges::begin(E)} is ill-formed.
\end{itemize}
\pnum
\begin{note}
Diagnosable ill-formed cases above
result in substitution failure when \tcode{ranges::begin(E)}
appears in the immediate context of a template instantiation.
\end{note}
\pnum
\begin{note}
Whenever \tcode{ranges::begin(E)} is a valid expression, its type models
\libconcept{input_or_output_iterator}.
\end{note}
\rSec2[range.access.end]{\tcode{ranges::end}}
\indexlibraryglobal{end}%
\pnum
The name \tcode{ranges::end} denotes a customization point
object\iref{customization.point.object}.
\pnum
Given a subexpression \tcode{E} with type \tcode{T},
let \tcode{t} be an lvalue that denotes the reified object for \tcode{E}.
Then:
\begin{itemize}
\item
If \tcode{E} is an rvalue and
\tcode{enable_borrowed_range<remove_cv_t<T>>} is \tcode{false},
\tcode{ranges::end(E)} is ill-formed.
\item
Otherwise, if \tcode{T} is an array type\iref{term.array.type} and
\tcode{remove_all_extents_t<T>} is an incomplete type,
\tcode{ranges::end(E)} is ill-formed with no diagnostic required.
\item
Otherwise, if \tcode{T} is an array of unknown bound,
\tcode{ranges::end(E)} is ill-formed.
\item
Otherwise, if \tcode{T} is an array,
\tcode{ranges::end(E)} is expression-equivalent to
\tcode{t + extent_v<T>}.
\item
Otherwise, if \tcode{auto(t.end())}
is a valid expression whose type models
\tcode{\libconcept{sentinel_for}<iterator_t<T>>}
then \tcode{ranges::end(E)} is expression-equivalent to
\tcode{auto(t.end())}.
\item
Otherwise, if \tcode{T} is a class or enumeration type and
\tcode{auto(end(t))}
is a valid expression whose type models
\tcode{\libconcept{sentinel_for}<iterator_t<T>>}
where the meaning of \tcode{end} is established as-if by performing
argument-dependent lookup only\iref{basic.lookup.argdep},
then \tcode{ranges::end(E)} is expression-equivalent to
that expression.
\item
Otherwise, \tcode{ranges::end(E)} is ill-formed.
\end{itemize}
\pnum
\begin{note}
Diagnosable ill-formed cases above
result in substitution failure when \tcode{ranges::end(E)}
appears in the immediate context of a template instantiation.
\end{note}
\pnum
\begin{note}
Whenever \tcode{ranges::end(E)} is a valid expression,
the types \tcode{S} and \tcode{I} of
\tcode{ranges::end(E)} and \tcode{ranges::begin(E)}
model \tcode{\libconcept{sentinel_for}<S, I>}.
\end{note}
\rSec2[range.access.cbegin]{\tcode{ranges::cbegin}}
\indexlibraryglobal{cbegin}%
\pnum
The name \tcode{ranges::cbegin} denotes a customization point
object\iref{customization.point.object}.
Given a subexpression \tcode{E} with type \tcode{T},
let \tcode{t} be an lvalue that denotes the reified object for \tcode{E}.
Then:
\begin{itemize}
\item
If \tcode{E} is an rvalue and
\tcode{enable_borrowed_range<remove_cv_t<T>>} is \tcode{false},
\tcode{ranges::cbegin(E)} is ill-formed.
\item
Otherwise,
let \tcode{U} be \tcode{ranges::begin(\exposid{possibly-const-range}(t))}.
\tcode{ranges::cbegin(E)} is expression-equivalent to
\tcode{const_iterator<decltype(U)>(U)}.
\end{itemize}
\pnum
\begin{note}
Whenever \tcode{ranges::cbegin(E)} is a valid expression, its type models
\libconcept{input_or_output_iterator} and \exposconcept{constant-iterator}.
\end{note}
\rSec2[range.access.cend]{\tcode{ranges::cend}}
\indexlibraryglobal{cend}%
\pnum
The name \tcode{ranges::cend} denotes a customization point
object\iref{customization.point.object}.
Given a subexpression \tcode{E} with type \tcode{T},
let \tcode{t} be an lvalue that denotes the reified object for \tcode{E}.
Then:
\begin{itemize}
\item
If \tcode{E} is an rvalue and
\tcode{enable_borrowed_range<remove_cv_t<T>>} is \tcode{false},
\tcode{ranges::cend(E)} is ill-formed.
\item
Otherwise,
let \tcode{U} be \tcode{ranges::end(\exposid{possibly-const-range}(t))}.
\tcode{ranges::cend(E)} is expression-equivalent to
\tcode{const_sentinel<decltype(U)>(U)}.
\end{itemize}
\pnum
\begin{note}
Whenever \tcode{ranges::cend(E)} is a valid expression,
the types \tcode{S} and \tcode{I} of the expressions
\tcode{ranges::cend(E)} and \tcode{ranges::cbegin(E)}
model \tcode{\libconcept{sentinel_for}<S, I>}.
If \tcode{S} models \libconcept{input_iterator},
then \tcode{S} also models \exposconceptx{constant-itera\-tor}{constant-iterator}.
\end{note}
\rSec2[range.access.rbegin]{\tcode{ranges::rbegin}}
\indexlibraryglobal{rbegin}%
\pnum
The name \tcode{ranges::rbegin} denotes a customization point
object\iref{customization.point.object}.
\pnum
Given a subexpression \tcode{E} with type \tcode{T},
let \tcode{t} be an lvalue that denotes the reified object for \tcode{E}.
Then:
\begin{itemize}
\item
If \tcode{E} is an rvalue and
\tcode{enable_borrowed_range<remove_cv_t<T>>} is \tcode{false},
\tcode{ranges::rbegin(E)} is ill-formed.
\item
Otherwise, if \tcode{T} is an array type\iref{term.array.type} and
\tcode{remove_all_extents_t<T>} is an incomplete type,
\tcode{ranges::rbegin(E)} is ill-formed with no diagnostic required.
\item
Otherwise, if \tcode{auto(t.rbegin())}
is a valid expression whose type models
\libconcept{input_or_output_iterator},
\tcode{ranges::rbegin(E)} is expression-equivalent to
\tcode{auto(t.rbegin())}.
\item
Otherwise, if \tcode{T} is a class or enumeration type and
\tcode{auto(rbegin(t))}
is a valid expression whose type models
\libconcept{input_or_output_iterator}
where the meaning of \tcode{rbegin} is established as-if by performing
argument-dependent lookup only\iref{basic.lookup.argdep},
then \tcode{ranges::rbegin(E)} is expression-equivalent to
that expression.
\item
Otherwise, if both \tcode{ranges::begin(t)} and \tcode{ranges::end(t)}
are valid expressions of the same type which models
\libconcept{bidirectional_iterator}\iref{iterator.concept.bidir},
\tcode{ranges::rbegin(E)} is expression-equivalent to
\tcode{make_reverse_iterator(ranges::end(t))}.
\item
Otherwise, \tcode{ranges::rbegin(E)} is ill-formed.
\end{itemize}
\pnum
\begin{note}
Diagnosable ill-formed cases above result in substitution failure
when \tcode{ranges::rbegin(E)}
appears in the immediate context of a template instantiation.
\end{note}
\pnum
\begin{note}
Whenever \tcode{ranges::rbegin(E)} is a valid expression, its type models
\libconcept{input_or_output_iterator}.
\end{note}
\rSec2[range.access.rend]{\tcode{ranges::rend}}
\indexlibraryglobal{rend}%
\pnum
The name \tcode{ranges::rend} denotes a customization point
object\iref{customization.point.object}.
\pnum
Given a subexpression \tcode{E} with type \tcode{T},
let \tcode{t} be an lvalue that denotes the reified object for \tcode{E}.
Then:
\begin{itemize}
\item
If \tcode{E} is an rvalue and
\tcode{enable_borrowed_range<remove_cv_t<T>>} is \tcode{false},
\tcode{ranges::rend(E)} is ill-formed.
\item
Otherwise, if \tcode{T} is an array type\iref{term.array.type} and
\tcode{remove_all_extents_t<T>} is an incomplete type,
\tcode{ranges::rend(E)} is ill-formed with no diagnostic required.
\item
Otherwise, if \tcode{auto(t.rend())}
is a valid expression whose type models
\tcode{\libconcept{sentinel_for}<decltype(\brk{}ranges::rbegin(E))>}
then \tcode{ranges::rend(E)} is expression-equivalent to
\tcode{auto(t.rend())}.
\item
Otherwise, if \tcode{T} is a class or enumeration type and
\tcode{auto(rend(t))}
is a valid expression whose type models
\tcode{\libconcept{sentinel_for}<decltype(ranges::rbegin(E))>}
where the meaning of \tcode{rend} is established as-if by performing
argument-dependent lookup only\iref{basic.lookup.argdep},
then \tcode{ranges::rend(E)} is expression-equivalent to
that expression.
\item
Otherwise, if both \tcode{ranges::begin(t)} and \tcode{ranges::end(t)}
are valid expressions of the same type which models
\libconcept{bidirectional_iterator}\iref{iterator.concept.bidir},
then \tcode{ranges::rend(E)} is expression-equivalent to
\tcode{make_reverse_iterator(ranges::begin(t))}.
\item
Otherwise, \tcode{ranges::rend(E)} is ill-formed.
\end{itemize}
\pnum
\begin{note}
Diagnosable ill-formed cases above
result in substitution failure when \tcode{ranges::rend(E)}
appears in the immediate context of a template instantiation.
\end{note}
\pnum
\begin{note}
Whenever \tcode{ranges::rend(E)} is a valid expression,
the types \tcode{S} and \tcode{I} of the expressions
\tcode{ranges::rend(E)} and \tcode{ranges::rbegin(E)}
model \tcode{\libconcept{sentinel_for}<S, I>}.
\end{note}
\rSec2[range.access.crbegin]{\tcode{ranges::crbegin}}
\indexlibraryglobal{crbegin}%
\pnum
The name \tcode{ranges::crbegin} denotes a customization point
object\iref{customization.point.object}.
Given a subexpression \tcode{E} with type \tcode{T},
let \tcode{t} be an lvalue that denotes the reified object for \tcode{E}.
Then:
\begin{itemize}
\item
If \tcode{E} is an rvalue and
\tcode{enable_borrowed_range<remove_cv_t<T>>} is \tcode{false},
\tcode{ranges::crbegin(E)} is ill-formed.
\item
Otherwise,
let \tcode{U} be \tcode{ranges::rbegin(\exposid{possibly-const-range}(t))}.
\tcode{ranges::crbegin(E)} is expres\-sion-equivalent to
\tcode{const_iterator<decltype(U)>(U)}.
\end{itemize}
\pnum
\begin{note}
Whenever \tcode{ranges::crbegin(E)} is a valid expression, its
type models \libconcept{input_or_output_iterator} and
\exposconcept{constant-iterator}.
\end{note}
\rSec2[range.access.crend]{\tcode{ranges::crend}}
\indexlibraryglobal{crend}%
\pnum
The name \tcode{ranges::crend} denotes a customization point
object\iref{customization.point.object}.
Given a subexpression \tcode{E} with type \tcode{T},
let \tcode{t} be an lvalue that denotes the reified object for \tcode{E}.
Then:
\begin{itemize}
\item
If \tcode{E} is an rvalue and
\tcode{enable_borrowed_range<remove_cv_t<T>>} is \tcode{false},
\tcode{ranges::crend(E)} is ill-formed.
\item
Otherwise,
let \tcode{U} be \tcode{ranges::rend(\exposid{possibly-const-range}(t))}.
\tcode{ranges::crend(E)} is expression-equivalent to
\tcode{const_sentinel<decltype(U)>(U)}.
\end{itemize}
\pnum
\begin{note}
Whenever \tcode{ranges::crend(E)} is a valid expression,
the types \tcode{S} and \tcode{I} of the expressions
\tcode{ranges::crend(E)} and \tcode{ranges::crbegin(E)}
model \tcode{\libconcept{sentinel_for}<S, I>}.
If \tcode{S} models \libconcept{input_iterator},
then \tcode{S} also models \exposconceptx{constant-itera\-tor}{constant-iterator}.
\end{note}
\rSec2[range.prim.size]{\tcode{ranges::size}}
\indexlibraryglobal{size}%
\pnum