xref: /freebsd/contrib/llvm-project/libcxx/include/ranges (revision 963f5dc7a30624e95d72fb7f87b8892651164e46)
1// -*- C++ -*-
2//===--------------------------- ranges -----------------------------------===//
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<R&>()));
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  // [range.all], all view
124  namespace views {
125    inline constexpr unspecified all = unspecified;
126
127    template<viewable_range R>
128      using all_t = decltype(all(declval<R>()));
129  }
130
131  template<range R>
132    requires is_object_v<R>
133  class ref_view;
134
135  template<class T>
136    inline constexpr bool enable_borrowed_range<ref_view<T>> = true;
137
138  // [range.drop], drop view
139  template<view V>
140    class drop_view;
141
142  template<class T>
143    inline constexpr bool enable_borrowed_range<drop_view<T>> = enable_borrowed_range<T>;
144
145  // [range.transform], transform view
146  template<input_range V, copy_constructible F>
147    requires view<V> && is_object_v<F> &&
148             regular_invocable<F&, range_reference_t<V>> &&
149             can-reference<invoke_result_t<F&, range_reference_t<V>>>
150  class transform_view;
151
152  // [range.common], common view
153  template<view V>
154    requires (!common_range<V> && copyable<iterator_t<V>>)
155  class common_view;
156
157  template<class T>
158  inline constexpr bool enable_borrowed_range<common_view<T>> = enable_borrowed_range<T>;
159}
160
161*/
162
163// Make sure all feature tests macros are always available.
164#include <version>
165// Only enable the contents of the header when libc++ was build with LIBCXX_ENABLE_INCOMPLETE_FEATURES enabled
166#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
167
168#include <__config>
169#include <__ranges/access.h>
170#include <__ranges/all.h>
171#include <__ranges/common_view.h>
172#include <__ranges/concepts.h>
173#include <__ranges/dangling.h>
174#include <__ranges/data.h>
175#include <__ranges/drop_view.h>
176#include <__ranges/empty.h>
177#include <__ranges/empty_view.h>
178#include <__ranges/enable_borrowed_range.h>
179#include <__ranges/enable_view.h>
180#include <__ranges/ref_view.h>
181#include <__ranges/size.h>
182#include <__ranges/subrange.h>
183#include <__ranges/transform_view.h>
184#include <__ranges/view_interface.h>
185#include <compare>          // Required by the standard.
186#include <initializer_list> // Required by the standard.
187#include <iterator>         // Required by the standard.
188#include <type_traits>
189
190#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
191#pragma GCC system_header
192#endif
193
194_LIBCPP_PUSH_MACROS
195#include <__undef_macros>
196
197_LIBCPP_BEGIN_NAMESPACE_STD
198
199#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
200
201#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
202
203_LIBCPP_END_NAMESPACE_STD
204
205_LIBCPP_POP_MACROS
206
207#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
208
209#endif // _LIBCPP_RANGES
210