xref: /freebsd/contrib/llvm-project/libcxx/include/ranges (revision 911f0260390e18cf85f3dbf2c719b593efdc1e3c)
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
53  // [range.sized], sized ranges
54  template<class>
55    inline constexpr bool disable_sized_range = false;
56
57  template<class T>
58    concept sized_range = ...;
59
60  // [range.view], views
61  template<class T>
62    inline constexpr bool enable_view = ...;
63
64  struct view_base { };
65
66  template<class T>
67    concept view = ...;
68
69  // [range.refinements], other range refinements
70  template<class R, class T>
71    concept output_range = see below;
72
73  template<class T>
74    concept input_range = see below;
75
76  template<class T>
77    concept forward_range = see below;
78
79  template<class T>
80  concept bidirectional_range = see below;
81
82  template<class T>
83  concept random_access_range = see below;
84
85  template<class T>
86  concept contiguous_range = see below;
87
88  template <class _Tp>
89    concept common_range = see below;
90
91  template<class T>
92  concept viewable_range = see below;
93
94  // [view.interface], class template view_interface
95  template<class D>
96    requires is_class_v<D> && same_as<D, remove_cv_t<D>>
97  class view_interface;
98
99  // [range.subrange], sub-ranges
100  enum class subrange_kind : bool { unsized, sized };
101
102  template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K = see below>
103    requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>)
104  class subrange;
105
106  template<class I, class S, subrange_kind K>
107    inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
108
109  // [range.dangling], dangling iterator handling
110  struct dangling;
111
112  template<range R>
113    using borrowed_iterator_t = see below;
114
115  template<range R>
116    using borrowed_subrange_t = see below;
117
118  // [range.elements], elements view
119  template<input_range V, size_t N>
120    requires see below
121  class elements_view;
122
123  template<class T, size_t N>
124    inline constexpr bool enable_borrowed_range<elements_view<T, N>> =
125      enable_borrowed_range<T>;
126
127  template<class R>
128    using keys_view = elements_view<R, 0>;
129  template<class R>
130    using values_view = elements_view<R, 1>;
131
132  namespace views {
133    template<size_t N>
134      inline constexpr unspecified elements = unspecified;
135    inline constexpr auto keys = elements<0>;
136    inline constexpr auto values = elements<1>;
137  }
138
139  // [range.empty], empty view
140  template<class T>
141    requires is_object_v<T>
142  class empty_view;
143
144  template<class T>
145    inline constexpr bool enable_borrowed_range<empty_view<T>> = true;
146
147  namespace views {
148    template<class T>
149      inline constexpr empty_view<T> empty{};
150  }
151
152  // [range.all], all view
153  namespace views {
154    inline constexpr unspecified all = unspecified;
155
156    template<viewable_range R>
157      using all_t = decltype(all(declval<R>()));
158  }
159
160  template<range R>
161    requires is_object_v<R>
162  class ref_view;
163
164  template<class T>
165    inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
166
167  template<range R>
168    requires see below
169  class owning_view;
170
171  template<class T>
172    inline constexpr bool enable_borrowed_range<owning_view<T>> = enable_borrowed_range<T>;
173
174  // [range.filter], filter view
175  template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
176    requires view<V> && is_object_v<Pred>
177  class filter_view;
178
179  namespace views {
180    inline constexpr unspecified filter = unspecified;
181  }
182
183  // [range.drop], drop view
184  template<view V>
185    class drop_view;
186
187  template<class T>
188    inline constexpr bool enable_borrowed_range<drop_view<T>> = enable_borrowed_range<T>;
189
190  // [range.drop.while], drop while view
191  template<view V, class Pred>
192    requires input_range<V> && is_object_v<Pred> &&
193             indirect_unary_predicate<const Pred, iterator_t<V>>
194    class drop_while_view;
195
196  template<class T, class Pred>
197    inline constexpr bool enable_borrowed_range<drop_while_view<T, Pred>> =
198      enable_borrowed_range<T>;
199
200  namespace views { inline constexpr unspecified drop_while = unspecified; }
201
202  // [range.transform], transform view
203  template<input_range V, copy_constructible F>
204    requires view<V> && is_object_v<F> &&
205             regular_invocable<F&, range_reference_t<V>> &&
206             can-reference<invoke_result_t<F&, range_reference_t<V>>>
207  class transform_view;
208
209  // [range.counted], counted view
210  namespace views { inline constexpr unspecified counted = unspecified; }
211
212  // [range.common], common view
213  template<view V>
214    requires (!common_range<V> && copyable<iterator_t<V>>)
215  class common_view;
216
217 // [range.reverse], reverse view
218  template<view V>
219    requires bidirectional_range<V>
220  class reverse_view;
221
222  template<class T>
223    inline constexpr bool enable_borrowed_range<reverse_view<T>> = enable_borrowed_range<T>;
224
225  template<class T>
226  inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;
227
228   // [range.take], take view
229  template<view> class take_view;
230
231  template<class T>
232  inline constexpr bool enable_borrowed_range<take_view<T>> = enable_borrowed_range<T>;
233
234    // [range.take.while], take while view
235  template<view V, class Pred>
236    requires input_range<V> && is_object_v<Pred> &&
237             indirect_unary_predicate<const Pred, iterator_t<V>>
238    class take_while_view;
239
240  namespace views { inline constexpr unspecified take_while = unspecified; }
241
242  template<copy_constructible T>
243    requires is_object_v<T>
244  class single_view;
245
246  template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
247    requires weakly-equality-comparable-with<W, Bound> && copyable<W>
248  class iota_view;
249
250  template<class W, class Bound>
251    inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
252
253  // [range.join], join view
254  template<input_range V>
255    requires view<V> && input_range<range_reference_t<V>>
256  class join_view;
257
258  // [range.lazy.split], lazy split view
259  template<class R>
260    concept tiny-range = see below;   // exposition only
261
262  template<input_range V, forward_range Pattern>
263    requires view<V> && view<Pattern> &&
264             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
265             (forward_range<V> || tiny-range<Pattern>)
266  class lazy_split_view;
267
268  // [range.split], split view
269  template<forward_range V, forward_range Pattern>
270    requires view<V> && view<Pattern> &&
271             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to>
272  class split_view;
273
274  namespace views {
275    inline constexpr unspecified lazy_split = unspecified;
276    inline constexpr unspecified split = unspecified;
277  }
278
279  // [range.istream], istream view
280  template<movable Val, class CharT, class Traits = char_traits<CharT>>
281    requires see below
282  class basic_istream_view;
283
284  template<class Val>
285    using istream_view = basic_istream_view<Val, char>;
286
287  template<class Val>
288    using wistream_view = basic_istream_view<Val, wchar_t>;
289
290  namespace views { template<class T> inline constexpr unspecified istream = unspecified; }
291
292  // [range.zip], zip view
293  template<input_range... Views>
294    requires (view<Views> && ...) && (sizeof...(Views) > 0)
295  class zip_view;        // C++2b
296
297  template<class... Views>
298    inline constexpr bool enable_borrowed_range<zip_view<Views...>> =    // C++2b
299      (enable_borrowed_range<Views> && ...);
300
301  namespace views { inline constexpr unspecified zip = unspecified; }    // C++2b
302
303  // [range.as.rvalue]
304  template <view V>
305    requires input_range<V>
306  class as_rvalue_view; // since C++23
307
308  namespace views { inline constexpr unspecified as_rvalue ) unspecified; } // since C++23
309}
310
311namespace std {
312  namespace views = ranges::views;
313
314  template<class T> struct tuple_size;
315  template<size_t I, class T> struct tuple_element;
316
317  template<class I, class S, ranges::subrange_kind K>
318  struct tuple_size<ranges::subrange<I, S, K>>
319    : integral_constant<size_t, 2> {};
320
321  template<class I, class S, ranges::subrange_kind K>
322  struct tuple_element<0, ranges::subrange<I, S, K>> {
323    using type = I;
324  };
325
326  template<class I, class S, ranges::subrange_kind K>
327  struct tuple_element<1, ranges::subrange<I, S, K>> {
328    using type = S;
329  };
330
331  template<class I, class S, ranges::subrange_kind K>
332  struct tuple_element<0, const ranges::subrange<I, S, K>> {
333    using type = I;
334  };
335
336  template<class I, class S, ranges::subrange_kind K>
337  struct tuple_element<1, const ranges::subrange<I, S, K>> {
338    using type = S;
339  };
340}
341*/
342
343#include <__assert> // all public C++ headers provide the assertion handler
344#include <__config>
345#include <__ranges/access.h>
346#include <__ranges/all.h>
347#include <__ranges/as_rvalue_view.h>
348#include <__ranges/common_view.h>
349#include <__ranges/concepts.h>
350#include <__ranges/counted.h>
351#include <__ranges/dangling.h>
352#include <__ranges/data.h>
353#include <__ranges/drop_view.h>
354#include <__ranges/drop_while_view.h>
355#include <__ranges/elements_view.h>
356#include <__ranges/empty.h>
357#include <__ranges/empty_view.h>
358#include <__ranges/enable_borrowed_range.h>
359#include <__ranges/enable_view.h>
360#include <__ranges/filter_view.h>
361#include <__ranges/iota_view.h>
362#include <__ranges/join_view.h>
363#include <__ranges/lazy_split_view.h>
364#include <__ranges/rbegin.h>
365#include <__ranges/ref_view.h>
366#include <__ranges/rend.h>
367#include <__ranges/reverse_view.h>
368#include <__ranges/single_view.h>
369#include <__ranges/size.h>
370#include <__ranges/split_view.h>
371#include <__ranges/subrange.h>
372#include <__ranges/take_view.h>
373#include <__ranges/take_while_view.h>
374#include <__ranges/transform_view.h>
375#include <__ranges/view_interface.h>
376#include <__ranges/views.h>
377#include <__ranges/zip_view.h>
378#include <type_traits>
379#include <version>
380
381#if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
382#include <__ranges/istream_view.h>
383#endif
384
385// standard-mandated includes
386
387// [ranges.syn]
388#include <compare>
389#include <initializer_list>
390#include <iterator>
391
392// [tuple.helper]
393#include <__tuple_dir/tuple_element.h>
394#include <__tuple_dir/tuple_size.h>
395
396#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
397#  pragma GCC system_header
398#endif
399
400#endif // _LIBCPP_RANGES
401