1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
// RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s
// RUN: %clang_cc1 -std=c++2c -verify=ref,both %s
// both-no-diagnostics
namespace std {
inline namespace {
template <class _Tp, _Tp __v> struct integral_constant {
static const _Tp value = __v;
};
template <bool _Val> using _BoolConstant = integral_constant<bool, _Val>;
template <class _Tp> using __remove_cv_t = __remove_cv(_Tp);
template <class _Tp> using remove_cv_t = __remove_cv_t<_Tp>;
} // namespace
inline namespace __1 {
template <class _Tp>
using __libcpp_remove_reference_t = __remove_reference_t(_Tp);
template <bool, class _IfRes, class> using conditional_t = _IfRes;
template <class _Tp, class _Up>
using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
template <class _Tp> struct enable_if {
typedef _Tp type;
};
template <bool, class _Tp = void> using __enable_if_t = _Tp;
template <class _Bp, class _Dp>
constexpr bool is_base_of_v = __is_base_of(_Bp, _Dp);
template <class _Tp> _Tp __declval(long);
template <class _Tp> decltype(__declval<_Tp>(0)) declval();
template <class _Fp, class... _Args>
constexpr decltype(declval<_Fp>()(declval<_Args>()...))
__invoke(_Fp __f, _Args... __args) {
return (__f)((__args)...);
}
template <class, class _Fp, class... _Args> struct __invokable_r {
template <class _XFp, class... _XArgs>
static decltype(__invoke(declval<_XFp>(), declval<_XArgs>()...))
__try_call(int);
using _Result = decltype(__try_call<_Fp, _Args...>(0));
};
template <class _Func, class... _Args>
struct __invoke_result
: enable_if<typename __invokable_r<void, _Func, _Args...>::_Result> {};
template <class _Fn, class... _Args>
using invoke_result_t = __invoke_result<_Fn, _Args...>::type;
template <class _Tp> constexpr __libcpp_remove_reference_t<_Tp> &&move(_Tp &&);
template <class _From, class _To>
constexpr bool is_convertible_v = __is_convertible(_From, _To);
template <class _From, class _To>
concept convertible_to =
is_convertible_v<_From, _To> && requires { (declval<_From>()); };
template <class _Tp, class _Up>
concept __same_as_impl = _IsSame<_Tp, _Up>::value;
template <class _Tp, class _Up>
concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
template <class _Tp> using __remove_cvref_t = __remove_cvref(_Tp);
template <class _Tp> using remove_cvref_t = __remove_cvref_t<_Tp>;
template <class _Xp, class _Yp>
using __cond_res =
decltype(false ? declval<_Xp (&)()>()() : declval<_Yp (&)()>()());
template <class...> struct common_reference;
template <class... _Types>
using common_reference_t = common_reference<_Types...>::type;
template <class, class> struct __common_reference_sub_bullet3;
template <class _Tp, class _Up>
struct common_reference<_Tp, _Up> : __common_reference_sub_bullet3<_Tp, _Up> {};
template <class _Tp, class _Up>
requires requires { typename __cond_res<_Tp, _Up>; }
struct __common_reference_sub_bullet3<_Tp, _Up> {
using type = __cond_res<_Tp, _Up>;
};
template <class _Tp, class _Up>
concept common_reference_with =
same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>> &&
convertible_to<_Tp, common_reference_t<_Tp, _Up>> &&
convertible_to<_Up, common_reference_t<_Tp, _Up>>;
template <class _Tp>
using __make_const_lvalue_ref = __libcpp_remove_reference_t<_Tp>;
template <class _Lhs, class _Rhs>
concept assignable_from =
common_reference_with<__make_const_lvalue_ref<_Lhs>,
__make_const_lvalue_ref<_Rhs>> &&
requires(_Lhs __lhs, _Rhs __rhs) {
{ __lhs = (__rhs) };
};
template <class _Tp>
concept default_initializable = requires { _Tp{}; };
template <class _Tp> constexpr bool is_object_v = __is_object(_Tp);
template <class _Dp, class _Bp>
concept derived_from = is_base_of_v<_Bp, _Dp> && is_convertible_v<_Dp *, _Bp *>;
template <class _Tp, class _Up>
concept __weakly_equality_comparable_with = requires(
__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) {
{ __u };
};
template <class _Fn, class... _Args>
constexpr invoke_result_t<_Fn, _Args...> invoke(_Fn __f, _Args &&...__args) {
return __invoke((__f), (__args)...);
}
template <class _Fn, class... _Args>
concept invocable =
requires(_Fn __fn, _Args... __args) { invoke((__fn), (__args)...); };
template <class _Fn, class... _Args>
concept regular_invocable = invocable<_Fn, _Args...>;
template <template <class> class, class>
integral_constant<bool, false> __sfinae_test_impl();
template <template <class> class _Templ, class... _Args>
using _IsValidExpansion = decltype(__sfinae_test_impl<_Templ, _Args...>());
template <class _Tp>
using __test_for_primary_template =
__enable_if_t<_IsSame<_Tp, typename _Tp::__primary_template>::value>;
template <class _Tp>
using __is_primary_template =
_IsValidExpansion<__test_for_primary_template, _Tp>;
template <class> struct __cond_value_type;
template <class _Tp>
requires is_object_v<_Tp>
struct __cond_value_type<_Tp> {
using value_type = remove_cv_t<_Tp>;
};
template <class _Tp>
concept __has_member_value_type = requires { typename _Tp; };
template <class> struct indirectly_readable_traits;
template <class _Tp>
struct indirectly_readable_traits<_Tp *> : __cond_value_type<_Tp> {};
template <__has_member_value_type _Tp>
struct indirectly_readable_traits<_Tp>
: __cond_value_type<typename _Tp::value_type> {};
template <bool> struct _OrImpl;
template <> struct _OrImpl<true> {
template <class, class _First, class... _Rest>
using _Result =
_OrImpl<!bool() && sizeof...(_Rest)>::template _Result<_First, _Rest...>;
};
template <> struct _OrImpl<false> {
template <class _Res> using _Result = _Res;
};
template <class... _Args>
using _Or =
_OrImpl<sizeof...(_Args) !=
0>::template _Result<integral_constant<bool, false>, _Args...>;
template <class _Tp>
concept __dereferenceable = requires(_Tp __t) {
{ __t };
};
template <__dereferenceable _Tp>
using iter_reference_t = decltype(*declval<_Tp>());
struct input_iterator_tag {};
struct forward_iterator_tag : input_iterator_tag {};
struct bidirectional_iterator_tag : forward_iterator_tag {};
struct __iter_concept_random_fallback {
template <class>
using _Apply = __enable_if_t<__is_primary_template<int>::value,
bidirectional_iterator_tag>;
};
template <class _Tester> struct __test_iter_concept : _Tester {};
struct __iter_concept_cache {
using type = _Or<__test_iter_concept<__iter_concept_random_fallback>>;
};
template <class _Iter>
using _ITER_CONCEPT = __iter_concept_cache::type::_Apply<_Iter>;
template <class _Ip>
using iter_value_t =
conditional_t<__is_primary_template<int>::value,
indirectly_readable_traits<remove_cvref_t<_Ip>>,
int>::value_type;
namespace ranges {
struct Trans_NS___iter_move___fn {
template <class _Ip> auto operator()(_Ip __i) const -> decltype(std::move(*(__i)));
};
inline namespace {
auto iter_move = Trans_NS___iter_move___fn{};
}
} // namespace ranges
template <__dereferenceable _Tp>
requires requires {
{ ranges::iter_move };
}
using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<_Tp>()));
template <class _In>
concept __indirectly_readable_impl =
requires(_In __i) {
{ ranges::iter_move(__i) } -> same_as<iter_rvalue_reference_t<_In>>;
} && common_reference_with<iter_reference_t<_In>, iter_value_t<_In>> &&
common_reference_with<iter_reference_t<_In>,
iter_rvalue_reference_t<_In>> &&
common_reference_with<iter_rvalue_reference_t<_In>, iter_value_t<_In>>;
template <class _In>
concept indirectly_readable = __indirectly_readable_impl<remove_cvref_t<_In>>;
template <class _Tp> struct __indirect_value_t_impl {
using type = iter_value_t<_Tp>;
};
template <indirectly_readable _Tp>
using __indirect_value_t = __indirect_value_t_impl<_Tp>::type;
template <class _Sp, class _Ip>
concept sentinel_for = __weakly_equality_comparable_with<_Sp, _Ip>;
template <class _Ip>
concept input_iterator = requires { typename _ITER_CONCEPT<_Ip>; } &&
derived_from<_ITER_CONCEPT<_Ip>, input_iterator_tag>;
template <class _Fp, class _It>
concept indirectly_unary_invocable =
invocable<_Fp, __indirect_value_t<_It>> &&
invocable<_Fp, iter_reference_t<_It>> &&
common_reference_with<invoke_result_t<_Fp, __indirect_value_t<_It>>,
invoke_result_t<_Fp, iter_reference_t<_It>>>;
template <class _Fp, class _It>
concept indirectly_regular_unary_invocable =
regular_invocable<_Fp, __indirect_value_t<_It>> &&
regular_invocable<_Fp, iter_reference_t<_It>> &&
common_reference_with<invoke_result_t<_Fp, __indirect_value_t<_It>>,
invoke_result_t<_Fp, iter_reference_t<_It>>>;
template <class _Fp, class... _Its>
requires(indirectly_readable<_Its> && ...) &&
invocable<_Fp, iter_reference_t<_Its>...>
using indirect_result_t = invoke_result_t<_Fp, iter_reference_t<_Its>...>;
template <class _It, class _Proj> struct __projected_impl {
struct __type {
using value_type = remove_cvref_t<indirect_result_t<_Proj, _It>>;
indirect_result_t<_Proj, _It> operator*();
};
};
template <indirectly_readable _It,
indirectly_regular_unary_invocable<_It> _Proj>
using projected = __projected_impl<_It, _Proj>::__type;
namespace ranges {
template <class, class> using for_each_result = int;
struct Z {};
constexpr Z zomg() {
return {};
}
constexpr Z zomg2(Z z) {
return {};
}
struct __for_each {
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj,
indirectly_unary_invocable<projected<_Iter, _Proj>> _Func>
constexpr for_each_result<_Iter, _Func>
operator()(_Iter __first, _Sent __last, _Func __func, _Proj __proj) const {
for (; __first != __last; ++__first)
invoke(__func, invoke(__proj, *__first));
return {};
}
};
inline namespace {
auto for_each = __for_each{};
}
} // namespace ranges
} // namespace __1
} // namespace std
struct T {};
struct Proj {
constexpr void *operator()(T) { return nullptr; }
};
struct UnaryVoid {
constexpr void operator()(void *) {}
};
constexpr bool all_the_algorithms() {
T a[2];
T *last = a + 2;
std::ranges::for_each(a, last, UnaryVoid(), Proj());
return true;
}
static_assert(all_the_algorithms());
|