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.empty], empty view
119  template<class T>
120    requires is_object_v<T>
121  class empty_view;
122
123  template<class T>
124    inline constexpr bool enable_borrowed_range<empty_view<T>> = true;
125
126  namespace views {
127    template<class T>
128      inline constexpr empty_view<T> empty{};
129  }
130
131  // [range.all], all view
132  namespace views {
133    inline constexpr unspecified all = unspecified;
134
135    template<viewable_range R>
136      using all_t = decltype(all(declval<R>()));
137  }
138
139  template<range R>
140    requires is_object_v<R>
141  class ref_view;
142
143  template<class T>
144    inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
145
146  template<range R>
147    requires see below
148  class owning_view;
149
150  template<class T>
151    inline constexpr bool enable_borrowed_range<owning_view<T>> = enable_borrowed_range<T>;
152
153  // [range.filter], filter view
154  template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
155    requires view<V> && is_object_v<Pred>
156  class filter_view;
157
158  namespace views {
159    inline constexpr unspecified filter = unspecified;
160  }
161
162  // [range.drop], drop view
163  template<view V>
164    class drop_view;
165
166  template<class T>
167    inline constexpr bool enable_borrowed_range<drop_view<T>> = enable_borrowed_range<T>;
168
169  // [range.transform], transform view
170  template<input_range V, copy_constructible F>
171    requires view<V> && is_object_v<F> &&
172             regular_invocable<F&, range_reference_t<V>> &&
173             can-reference<invoke_result_t<F&, range_reference_t<V>>>
174  class transform_view;
175
176  // [range.counted], counted view
177  namespace views { inline constexpr unspecified counted = unspecified; }
178
179  // [range.common], common view
180  template<view V>
181    requires (!common_range<V> && copyable<iterator_t<V>>)
182  class common_view;
183
184 // [range.reverse], reverse view
185  template<view V>
186    requires bidirectional_range<V>
187  class reverse_view;
188
189  template<class T>
190    inline constexpr bool enable_borrowed_range<reverse_view<T>> = enable_borrowed_range<T>;
191
192  template<class T>
193  inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;
194
195   // [range.take], take view
196  template<view> class take_view;
197
198  template<class T>
199  inline constexpr bool enable_borrowed_range<take_view<T>> = enable_borrowed_range<T>;
200
201  template<copy_constructible T>
202    requires is_object_v<T>
203  class single_view;
204
205  template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
206    requires weakly-equality-comparable-with<W, Bound> && copyable<W>
207  class iota_view;
208
209  template<class W, class Bound>
210    inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
211
212  // [range.join], join view
213  template<input_range V>
214    requires view<V> && input_range<range_reference_t<V>>
215  class join_view;
216
217  // [range.lazy.split], lazy split view
218  template<class R>
219    concept tiny-range = see below;   // exposition only
220
221  template<input_range V, forward_range Pattern>
222    requires view<V> && view<Pattern> &&
223             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
224             (forward_range<V> || tiny-range<Pattern>)
225  class lazy_split_view;
226
227  namespace views {
228    inline constexpr unspecified lazy_split = unspecified;
229  }
230
231  // [range.zip], zip view
232  template<input_range... Views>
233    requires (view<Views> && ...) && (sizeof...(Views) > 0)
234  class zip_view;        // C++2b
235
236  template<class... Views>
237    inline constexpr bool enable_borrowed_range<zip_view<Views...>> =    // C++2b
238      (enable_borrowed_range<Views> && ...);
239
240  namespace views { inline constexpr unspecified zip = unspecified; }    // C++2b
241}
242
243namespace std {
244  namespace views = ranges::views;
245
246  template<class T> struct tuple_size;
247  template<size_t I, class T> struct tuple_element;
248
249  template<class I, class S, ranges::subrange_kind K>
250  struct tuple_size<ranges::subrange<I, S, K>>
251    : integral_constant<size_t, 2> {};
252
253  template<class I, class S, ranges::subrange_kind K>
254  struct tuple_element<0, ranges::subrange<I, S, K>> {
255    using type = I;
256  };
257
258  template<class I, class S, ranges::subrange_kind K>
259  struct tuple_element<1, ranges::subrange<I, S, K>> {
260    using type = S;
261  };
262
263  template<class I, class S, ranges::subrange_kind K>
264  struct tuple_element<0, const ranges::subrange<I, S, K>> {
265    using type = I;
266  };
267
268  template<class I, class S, ranges::subrange_kind K>
269  struct tuple_element<1, const ranges::subrange<I, S, K>> {
270    using type = S;
271  };
272}
273*/
274
275#include <__assert> // all public C++ headers provide the assertion handler
276#include <__config>
277#include <__ranges/access.h>
278#include <__ranges/all.h>
279#include <__ranges/common_view.h>
280#include <__ranges/concepts.h>
281#include <__ranges/counted.h>
282#include <__ranges/dangling.h>
283#include <__ranges/data.h>
284#include <__ranges/drop_view.h>
285#include <__ranges/empty.h>
286#include <__ranges/empty_view.h>
287#include <__ranges/enable_borrowed_range.h>
288#include <__ranges/enable_view.h>
289#include <__ranges/filter_view.h>
290#include <__ranges/iota_view.h>
291#include <__ranges/join_view.h>
292#include <__ranges/lazy_split_view.h>
293#include <__ranges/rbegin.h>
294#include <__ranges/ref_view.h>
295#include <__ranges/rend.h>
296#include <__ranges/reverse_view.h>
297#include <__ranges/single_view.h>
298#include <__ranges/size.h>
299#include <__ranges/subrange.h>
300#include <__ranges/take_view.h>
301#include <__ranges/transform_view.h>
302#include <__ranges/view_interface.h>
303#include <__ranges/views.h>
304#include <__ranges/zip_view.h>
305#include <__tuple> // TODO: <ranges> has to export std::tuple_size. Replace this, once <tuple> is granularized.
306#include <compare>          // Required by the standard.
307#include <initializer_list> // Required by the standard.
308#include <iterator>         // Required by the standard.
309#include <type_traits>
310#include <version>
311
312#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
313#  pragma GCC system_header
314#endif
315
316#endif // _LIBCPP_RANGES
317