xref: /freebsd/contrib/llvm-project/libcxx/include/ranges (revision 1db9f3b21e39176dd5b67cf8ac378633b172463e)
1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_RANGES
11#define _LIBCPP_RANGES
12
13/*
14
15#include <compare>              // see [compare.syn]
16#include <initializer_list>     // see [initializer.list.syn]
17#include <iterator>             // see [iterator.synopsis]
18
19namespace std::ranges {
20  inline namespace unspecified {
21    // [range.access], range access
22    inline constexpr unspecified begin = unspecified;
23    inline constexpr unspecified end = unspecified;
24    inline constexpr unspecified cbegin = unspecified;
25    inline constexpr unspecified cend = unspecified;
26
27    inline constexpr unspecified size = unspecified;
28    inline constexpr unspecified ssize = unspecified;
29  }
30
31  // [range.range], ranges
32  template<class T>
33    concept range = see below;
34
35  template<class T>
36    inline constexpr bool enable_borrowed_range = false;
37
38  template<class T>
39    using iterator_t = decltype(ranges::begin(declval<T&>()));
40  template<range R>
41    using sentinel_t = decltype(ranges::end(declval<R&>()));
42  template<range R>
43    using range_difference_t = iter_difference_t<iterator_t<R>>;
44  template<sized_range R>
45    using range_size_t = decltype(ranges::size(declval<R&>()));
46  template<range R>
47    using range_value_t = iter_value_t<iterator_t<R>>;
48  template<range R>
49    using range_reference_t = iter_reference_t<iterator_t<R>>;
50  template<range R>
51    using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<R>>;
52  template <range R>
53    using range_common_reference_t = iter_common_reference_t<iterator_t<R>>;
54
55  // [range.sized], sized ranges
56  template<class>
57    inline constexpr bool disable_sized_range = false;
58
59  template<class T>
60    concept sized_range = ...;
61
62  // [range.view], views
63  template<class T>
64    inline constexpr bool enable_view = ...;
65
66  struct view_base { };
67
68  template<class T>
69    concept view = ...;
70
71  // [range.refinements], other range refinements
72  template<class R, class T>
73    concept output_range = see below;
74
75  template<class T>
76    concept input_range = see below;
77
78  template<class T>
79    concept forward_range = see below;
80
81  template<class T>
82  concept bidirectional_range = see below;
83
84  template<class T>
85  concept random_access_range = see below;
86
87  template<class T>
88  concept contiguous_range = see below;
89
90  template <class _Tp>
91    concept common_range = see below;
92
93  template<class T>
94  concept viewable_range = see below;
95
96  // [view.interface], class template view_interface
97  template<class D>
98    requires is_class_v<D> && same_as<D, remove_cv_t<D>>
99  class view_interface;
100
101  // [range.subrange], sub-ranges
102  enum class subrange_kind : bool { unsized, sized };
103
104  template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K = see below>
105    requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
106  class subrange;
107
108  template<class I, class S, subrange_kind K>
109    inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
110
111  // [range.dangling], dangling iterator handling
112  struct dangling;
113
114  template<range R>
115    using borrowed_iterator_t = see below;
116
117  template<range R>
118    using borrowed_subrange_t = see below;
119
120  // [range.elements], elements view
121  template<input_range V, size_t N>
122    requires see below
123  class elements_view;
124
125  template<class T, size_t N>
126    inline constexpr bool enable_borrowed_range<elements_view<T, N>> =
127      enable_borrowed_range<T>;
128
129  template<class R>
130    using keys_view = elements_view<R, 0>;
131  template<class R>
132    using values_view = elements_view<R, 1>;
133
134  namespace views {
135    template<size_t N>
136      inline constexpr unspecified elements = unspecified;
137    inline constexpr auto keys = elements<0>;
138    inline constexpr auto values = elements<1>;
139  }
140
141  // [range.utility.conv], range conversions
142  template<class C, input_range R, class... Args> requires (!view<C>)
143    constexpr C to(R&& r, Args&&... args);     // Since C++23
144  template<template<class...> class C, input_range R, class... Args>
145    constexpr auto to(R&& r, Args&&... args);  // Since C++23
146  template<class C, class... Args> requires (!view<C>)
147    constexpr auto to(Args&&... args);         // Since C++23
148  template<template<class...> class C, class... Args>
149    constexpr auto to(Args&&... args);         // Since C++23
150
151  // [range.empty], empty view
152  template<class T>
153    requires is_object_v<T>
154  class empty_view;
155
156  template<class T>
157    inline constexpr bool enable_borrowed_range<empty_view<T>> = true;
158
159  namespace views {
160    template<class T>
161      inline constexpr empty_view<T> empty{};
162  }
163
164  // [range.all], all view
165  namespace views {
166    inline constexpr unspecified all = unspecified;
167
168    template<viewable_range R>
169      using all_t = decltype(all(declval<R>()));
170  }
171
172  template<range R>
173    requires is_object_v<R>
174  class ref_view;
175
176  template<class T>
177    inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
178
179  template<range R>
180    requires see below
181  class owning_view;
182
183  template<class T>
184    inline constexpr bool enable_borrowed_range<owning_view<T>> = enable_borrowed_range<T>;
185
186  // [range.filter], filter view
187  template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
188    requires view<V> && is_object_v<Pred>
189  class filter_view;
190
191  namespace views {
192    inline constexpr unspecified filter = unspecified;
193  }
194
195  // [range.drop], drop view
196  template<view V>
197    class drop_view;
198
199  template<class T>
200    inline constexpr bool enable_borrowed_range<drop_view<T>> = enable_borrowed_range<T>;
201
202  // [range.drop.while], drop while view
203  template<view V, class Pred>
204    requires input_range<V> && is_object_v<Pred> &&
205             indirect_unary_predicate<const Pred, iterator_t<V>>
206    class drop_while_view;
207
208  template<class T, class Pred>
209    inline constexpr bool enable_borrowed_range<drop_while_view<T, Pred>> =
210      enable_borrowed_range<T>;
211
212  namespace views { inline constexpr unspecified drop_while = unspecified; }
213
214  // [range.transform], transform view
215  template<input_range V, copy_constructible F>
216    requires view<V> && is_object_v<F> &&
217             regular_invocable<F&, range_reference_t<V>> &&
218             can-reference<invoke_result_t<F&, range_reference_t<V>>>
219  class transform_view;
220
221  // [range.counted], counted view
222  namespace views { inline constexpr unspecified counted = unspecified; }
223
224  // [range.common], common view
225  template<view V>
226    requires (!common_range<V> && copyable<iterator_t<V>>)
227  class common_view;
228
229 // [range.reverse], reverse view
230  template<view V>
231    requires bidirectional_range<V>
232  class reverse_view;
233
234  template<class T>
235    inline constexpr bool enable_borrowed_range<reverse_view<T>> = enable_borrowed_range<T>;
236
237  template<class T>
238  inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;
239
240   // [range.take], take view
241  template<view> class take_view;
242
243  template<class T>
244  inline constexpr bool enable_borrowed_range<take_view<T>> = enable_borrowed_range<T>;
245
246    // [range.take.while], take while view
247  template<view V, class Pred>
248    requires input_range<V> && is_object_v<Pred> &&
249             indirect_unary_predicate<const Pred, iterator_t<V>>
250    class take_while_view;
251
252  namespace views { inline constexpr unspecified take_while = unspecified; }
253
254  template<copy_constructible T>
255    requires is_object_v<T>
256  class single_view;
257
258  template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
259    requires weakly-equality-comparable-with<W, Bound> && copyable<W>
260  class iota_view;
261
262  template<class W, class Bound>
263    inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
264
265  // [range.repeat], repeat view
266  template<class T>
267    concept integer-like-with-usable-difference-type =  // exposition only
268      is-signed-integer-like<T> || (is-integer-like<T> && weakly_incrementable<T>);
269
270  template<move_constructible T, semiregular Bound = unreachable_sentinel_t>
271    requires (is_object_v<T> && same_as<T, remove_cv_t<T>> &&
272              (integer-like-with-usable-difference-type<Bound> ||
273               same_as<Bound, unreachable_sentinel_t>))
274  class repeat_view;
275
276  namespace views { inline constexpr unspecified repeat = unspecified; }
277
278  // [range.join], join view
279  template<input_range V>
280    requires view<V> && input_range<range_reference_t<V>>
281  class join_view;
282
283  // [range.lazy.split], lazy split view
284  template<class R>
285    concept tiny-range = see below;   // exposition only
286
287  template<input_range V, forward_range Pattern>
288    requires view<V> && view<Pattern> &&
289             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
290             (forward_range<V> || tiny-range<Pattern>)
291  class lazy_split_view;
292
293  // [range.split], split view
294  template<forward_range V, forward_range Pattern>
295    requires view<V> && view<Pattern> &&
296             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to>
297  class split_view;
298
299  namespace views {
300    inline constexpr unspecified lazy_split = unspecified;
301    inline constexpr unspecified split = unspecified;
302  }
303
304  // [range.istream], istream view
305  template<movable Val, class CharT, class Traits = char_traits<CharT>>
306    requires see below
307  class basic_istream_view;
308
309  template<class Val>
310    using istream_view = basic_istream_view<Val, char>;
311
312  template<class Val>
313    using wistream_view = basic_istream_view<Val, wchar_t>;
314
315  namespace views { template<class T> inline constexpr unspecified istream = unspecified; }
316
317  // [range.zip], zip view
318  template<input_range... Views>
319    requires (view<Views> && ...) && (sizeof...(Views) > 0)
320  class zip_view;        // C++23
321
322  template<class... Views>
323    inline constexpr bool enable_borrowed_range<zip_view<Views...>> =       // C++23
324      (enable_borrowed_range<Views> && ...);
325
326  namespace views { inline constexpr unspecified zip = unspecified; }       // C++23
327
328  // [range.as.rvalue]
329  template <view V>
330    requires input_range<V>
331  class as_rvalue_view;                                                     // C++23
332
333  namespace views { inline constexpr unspecified as_rvalue ) unspecified; } // C++23
334
335  [range.chunk.by]
336  template<forward_range V, indirect_binary_predicate<iterator_t<V>, iterator_t<V>> Pred>
337    requires view<V> && is_object_v<Pred>
338  class chunk_by_view;                                                      // C++23
339
340  namespace views { inline constexpr unspecified chunk_by = unspecified; }  // C++23
341}
342
343namespace std {
344  namespace views = ranges::views;
345
346  template<class T> struct tuple_size;
347  template<size_t I, class T> struct tuple_element;
348
349  template<class I, class S, ranges::subrange_kind K>
350  struct tuple_size<ranges::subrange<I, S, K>>
351    : integral_constant<size_t, 2> {};
352
353  template<class I, class S, ranges::subrange_kind K>
354  struct tuple_element<0, ranges::subrange<I, S, K>> {
355    using type = I;
356  };
357
358  template<class I, class S, ranges::subrange_kind K>
359  struct tuple_element<1, ranges::subrange<I, S, K>> {
360    using type = S;
361  };
362
363  template<class I, class S, ranges::subrange_kind K>
364  struct tuple_element<0, const ranges::subrange<I, S, K>> {
365    using type = I;
366  };
367
368  template<class I, class S, ranges::subrange_kind K>
369  struct tuple_element<1, const ranges::subrange<I, S, K>> {
370    using type = S;
371  };
372
373  struct from_range_t { explicit from_range_t() = default; };  // Since C++23
374  inline constexpr from_range_t from_range{};                  // Since C++23
375}
376*/
377
378#include <__assert> // all public C++ headers provide the assertion handler
379#include <__config>
380#include <__ranges/access.h>
381#include <__ranges/all.h>
382#include <__ranges/as_rvalue_view.h>
383#include <__ranges/chunk_by_view.h>
384#include <__ranges/common_view.h>
385#include <__ranges/concepts.h>
386#include <__ranges/counted.h>
387#include <__ranges/dangling.h>
388#include <__ranges/data.h>
389#include <__ranges/drop_view.h>
390#include <__ranges/drop_while_view.h>
391#include <__ranges/elements_view.h>
392#include <__ranges/empty.h>
393#include <__ranges/empty_view.h>
394#include <__ranges/enable_borrowed_range.h>
395#include <__ranges/enable_view.h>
396#include <__ranges/filter_view.h>
397#include <__ranges/from_range.h>
398#include <__ranges/iota_view.h>
399#include <__ranges/join_view.h>
400#include <__ranges/lazy_split_view.h>
401#include <__ranges/rbegin.h>
402#include <__ranges/ref_view.h>
403#include <__ranges/rend.h>
404#include <__ranges/repeat_view.h>
405#include <__ranges/reverse_view.h>
406#include <__ranges/single_view.h>
407#include <__ranges/size.h>
408#include <__ranges/split_view.h>
409#include <__ranges/subrange.h>
410#include <__ranges/take_view.h>
411#include <__ranges/take_while_view.h>
412#include <__ranges/to.h>
413#include <__ranges/transform_view.h>
414#include <__ranges/view_interface.h>
415#include <__ranges/views.h>
416#include <__ranges/zip_view.h>
417#include <version>
418
419#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
420#  include <__ranges/istream_view.h>
421#endif
422
423// standard-mandated includes
424
425// [ranges.syn]
426#include <compare>
427#include <initializer_list>
428#include <iterator>
429
430// [tuple.helper]
431#include <__tuple/tuple_element.h>
432#include <__tuple/tuple_size.h>
433
434#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
435#  pragma GCC system_header
436#endif
437
438#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
439#  include <cstdlib>
440#  include <iosfwd>
441#  include <type_traits>
442#endif
443
444#endif // _LIBCPP_RANGES
445