2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_RANGES
11 #define _LIBCPP_RANGES
15 #include <compare> // see [compare.syn]
16 #include <initializer_list> // see [initializer.list.syn]
17 #include <iterator> // see [iterator.synopsis]
19 namespace 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;
27 inline constexpr unspecified size = unspecified;
28 inline constexpr unspecified ssize = unspecified;
31 // [range.range], ranges
33 concept range = see below;
36 inline constexpr bool enable_borrowed_range = false;
39 using iterator_t = decltype(ranges::begin(declval<T&>()));
41 using sentinel_t = decltype(ranges::end(declval<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&>()));
47 using range_value_t = iter_value_t<iterator_t<R>>;
49 using range_reference_t = iter_reference_t<iterator_t<R>>;
51 using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<R>>;
53 // [range.sized], sized ranges
55 inline constexpr bool disable_sized_range = false;
58 concept sized_range = ...;
60 // [range.view], views
62 inline constexpr bool enable_view = ...;
69 // [range.refinements], other range refinements
70 template<class R, class T>
71 concept output_range = see below;
74 concept input_range = see below;
77 concept forward_range = see below;
80 concept bidirectional_range = see below;
83 concept random_access_range = see below;
86 concept contiguous_range = see below;
89 concept common_range = see below;
92 concept viewable_range = see below;
94 // [view.interface], class template view_interface
96 requires is_class_v<D> && same_as<D, remove_cv_t<D>>
99 // [range.subrange], sub-ranges
100 enum class subrange_kind : bool { unsized, sized };
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>)
106 template<class I, class S, subrange_kind K>
107 inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
109 // [range.dangling], dangling iterator handling
113 using borrowed_iterator_t = see below;
116 using borrowed_subrange_t = see below;
118 // [range.empty], empty view
120 requires is_object_v<T>
123 // [range.all], all view
125 inline constexpr unspecified all = unspecified;
127 template<viewable_range R>
128 using all_t = decltype(all(declval<R>()));
132 requires is_object_v<R>
136 inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
143 inline constexpr bool enable_borrowed_range<owning_view<T>> = enable_borrowed_range<T>;
145 // [range.drop], drop view
150 inline constexpr bool enable_borrowed_range<drop_view<T>> = enable_borrowed_range<T>;
152 // [range.transform], transform view
153 template<input_range V, copy_constructible F>
154 requires view<V> && is_object_v<F> &&
155 regular_invocable<F&, range_reference_t<V>> &&
156 can-reference<invoke_result_t<F&, range_reference_t<V>>>
157 class transform_view;
159 // [range.counted], counted view
160 namespace views { inline constexpr unspecified counted = unspecified; }
162 // [range.common], common view
164 requires (!common_range<V> && copyable<iterator_t<V>>)
167 // [range.reverse], reverse view
169 requires bidirectional_range<V>
173 inline constexpr bool enable_borrowed_range<reverse_view<T>> = enable_borrowed_range<T>;
176 inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;
178 // [range.take], take view
179 template<view> class take_view;
182 inline constexpr bool enable_borrowed_range<take_view<T>> = enable_borrowed_range<T>;
184 template<copy_constructible T>
185 requires is_object_v<T>
188 template<weakly_incrementable W, semiregular Bound = unreachable_sentinel_t>
189 requires weakly-equality-comparable-with<W, Bound> && copyable<W>
192 template<class W, class Bound>
193 inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
195 // [range.join], join view
196 template<input_range V>
197 requires view<V> && input_range<range_reference_t<V>>
203 // Make sure all feature-test macros are available.
205 // Enable the contents of the header only when libc++ was built with LIBCXX_ENABLE_INCOMPLETE_FEATURES.
206 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
209 #include <__ranges/access.h>
210 #include <__ranges/all.h>
211 #include <__ranges/common_view.h>
212 #include <__ranges/concepts.h>
213 #include <__ranges/counted.h>
214 #include <__ranges/dangling.h>
215 #include <__ranges/data.h>
216 #include <__ranges/drop_view.h>
217 #include <__ranges/empty.h>
218 #include <__ranges/empty_view.h>
219 #include <__ranges/enable_borrowed_range.h>
220 #include <__ranges/enable_view.h>
221 #include <__ranges/iota_view.h>
222 #include <__ranges/join_view.h>
223 #include <__ranges/ref_view.h>
224 #include <__ranges/reverse_view.h>
225 #include <__ranges/single_view.h>
226 #include <__ranges/size.h>
227 #include <__ranges/subrange.h>
228 #include <__ranges/take_view.h>
229 #include <__ranges/transform_view.h>
230 #include <__ranges/view_interface.h>
231 #include <compare> // Required by the standard.
232 #include <initializer_list> // Required by the standard.
233 #include <iterator> // Required by the standard.
234 #include <type_traits>
236 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
237 #pragma GCC system_header
240 _LIBCPP_BEGIN_NAMESPACE_STD
242 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
244 namespace views = ranges::views;
246 #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
248 _LIBCPP_END_NAMESPACE_STD
250 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
252 #endif // _LIBCPP_RANGES