150
|
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_FUNCTIONAL_BASE
|
|
11 #define _LIBCPP_FUNCTIONAL_BASE
|
|
12
|
|
13 #include <__config>
|
221
|
14 #include <exception>
|
|
15 #include <new>
|
150
|
16 #include <type_traits>
|
|
17 #include <typeinfo>
|
|
18 #include <utility>
|
|
19
|
|
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
|
21 #pragma GCC system_header
|
|
22 #endif
|
|
23
|
|
24 _LIBCPP_BEGIN_NAMESPACE_STD
|
|
25
|
|
26 template <class _Arg1, class _Arg2, class _Result>
|
|
27 struct _LIBCPP_TEMPLATE_VIS binary_function
|
|
28 {
|
|
29 typedef _Arg1 first_argument_type;
|
|
30 typedef _Arg2 second_argument_type;
|
|
31 typedef _Result result_type;
|
|
32 };
|
|
33
|
|
34 template <class _Tp>
|
|
35 struct __has_result_type
|
|
36 {
|
|
37 private:
|
|
38 struct __two {char __lx; char __lxx;};
|
|
39 template <class _Up> static __two __test(...);
|
|
40 template <class _Up> static char __test(typename _Up::result_type* = 0);
|
|
41 public:
|
|
42 static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
|
43 };
|
|
44
|
|
45 #if _LIBCPP_STD_VER > 11
|
|
46 template <class _Tp = void>
|
|
47 #else
|
|
48 template <class _Tp>
|
|
49 #endif
|
|
50 struct _LIBCPP_TEMPLATE_VIS less : binary_function<_Tp, _Tp, bool>
|
|
51 {
|
221
|
52 typedef bool __result_type; // used by valarray
|
150
|
53 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
|
|
54 bool operator()(const _Tp& __x, const _Tp& __y) const
|
|
55 {return __x < __y;}
|
|
56 };
|
|
57
|
|
58 #if _LIBCPP_STD_VER > 11
|
|
59 template <>
|
|
60 struct _LIBCPP_TEMPLATE_VIS less<void>
|
|
61 {
|
|
62 template <class _T1, class _T2>
|
|
63 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
|
|
64 auto operator()(_T1&& __t, _T2&& __u) const
|
|
65 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
|
|
66 -> decltype (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
|
|
67 { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
|
|
68 typedef void is_transparent;
|
|
69 };
|
|
70 #endif
|
|
71
|
|
72 // __weak_result_type
|
|
73
|
|
74 template <class _Tp>
|
|
75 struct __derives_from_unary_function
|
|
76 {
|
|
77 private:
|
|
78 struct __two {char __lx; char __lxx;};
|
|
79 static __two __test(...);
|
|
80 template <class _Ap, class _Rp>
|
|
81 static unary_function<_Ap, _Rp>
|
|
82 __test(const volatile unary_function<_Ap, _Rp>*);
|
|
83 public:
|
|
84 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
|
|
85 typedef decltype(__test((_Tp*)0)) type;
|
|
86 };
|
|
87
|
|
88 template <class _Tp>
|
|
89 struct __derives_from_binary_function
|
|
90 {
|
|
91 private:
|
|
92 struct __two {char __lx; char __lxx;};
|
|
93 static __two __test(...);
|
|
94 template <class _A1, class _A2, class _Rp>
|
|
95 static binary_function<_A1, _A2, _Rp>
|
|
96 __test(const volatile binary_function<_A1, _A2, _Rp>*);
|
|
97 public:
|
|
98 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
|
|
99 typedef decltype(__test((_Tp*)0)) type;
|
|
100 };
|
|
101
|
|
102 template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
|
|
103 struct __maybe_derive_from_unary_function // bool is true
|
|
104 : public __derives_from_unary_function<_Tp>::type
|
|
105 {
|
|
106 };
|
|
107
|
|
108 template <class _Tp>
|
|
109 struct __maybe_derive_from_unary_function<_Tp, false>
|
|
110 {
|
|
111 };
|
|
112
|
|
113 template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
|
|
114 struct __maybe_derive_from_binary_function // bool is true
|
|
115 : public __derives_from_binary_function<_Tp>::type
|
|
116 {
|
|
117 };
|
|
118
|
|
119 template <class _Tp>
|
|
120 struct __maybe_derive_from_binary_function<_Tp, false>
|
|
121 {
|
|
122 };
|
|
123
|
|
124 template <class _Tp, bool = __has_result_type<_Tp>::value>
|
|
125 struct __weak_result_type_imp // bool is true
|
|
126 : public __maybe_derive_from_unary_function<_Tp>,
|
|
127 public __maybe_derive_from_binary_function<_Tp>
|
|
128 {
|
|
129 typedef _LIBCPP_NODEBUG_TYPE typename _Tp::result_type result_type;
|
|
130 };
|
|
131
|
|
132 template <class _Tp>
|
|
133 struct __weak_result_type_imp<_Tp, false>
|
|
134 : public __maybe_derive_from_unary_function<_Tp>,
|
|
135 public __maybe_derive_from_binary_function<_Tp>
|
|
136 {
|
|
137 };
|
|
138
|
|
139 template <class _Tp>
|
|
140 struct __weak_result_type
|
|
141 : public __weak_result_type_imp<_Tp>
|
|
142 {
|
|
143 };
|
|
144
|
|
145 // 0 argument case
|
|
146
|
|
147 template <class _Rp>
|
|
148 struct __weak_result_type<_Rp ()>
|
|
149 {
|
|
150 typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
|
|
151 };
|
|
152
|
|
153 template <class _Rp>
|
|
154 struct __weak_result_type<_Rp (&)()>
|
|
155 {
|
|
156 typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
|
|
157 };
|
|
158
|
|
159 template <class _Rp>
|
|
160 struct __weak_result_type<_Rp (*)()>
|
|
161 {
|
|
162 typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
|
|
163 };
|
|
164
|
|
165 // 1 argument case
|
|
166
|
|
167 template <class _Rp, class _A1>
|
|
168 struct __weak_result_type<_Rp (_A1)>
|
|
169 : public unary_function<_A1, _Rp>
|
|
170 {
|
|
171 };
|
|
172
|
|
173 template <class _Rp, class _A1>
|
|
174 struct __weak_result_type<_Rp (&)(_A1)>
|
|
175 : public unary_function<_A1, _Rp>
|
|
176 {
|
|
177 };
|
|
178
|
|
179 template <class _Rp, class _A1>
|
|
180 struct __weak_result_type<_Rp (*)(_A1)>
|
|
181 : public unary_function<_A1, _Rp>
|
|
182 {
|
|
183 };
|
|
184
|
|
185 template <class _Rp, class _Cp>
|
|
186 struct __weak_result_type<_Rp (_Cp::*)()>
|
|
187 : public unary_function<_Cp*, _Rp>
|
|
188 {
|
|
189 };
|
|
190
|
|
191 template <class _Rp, class _Cp>
|
|
192 struct __weak_result_type<_Rp (_Cp::*)() const>
|
|
193 : public unary_function<const _Cp*, _Rp>
|
|
194 {
|
|
195 };
|
|
196
|
|
197 template <class _Rp, class _Cp>
|
|
198 struct __weak_result_type<_Rp (_Cp::*)() volatile>
|
|
199 : public unary_function<volatile _Cp*, _Rp>
|
|
200 {
|
|
201 };
|
|
202
|
|
203 template <class _Rp, class _Cp>
|
|
204 struct __weak_result_type<_Rp (_Cp::*)() const volatile>
|
|
205 : public unary_function<const volatile _Cp*, _Rp>
|
|
206 {
|
|
207 };
|
|
208
|
|
209 // 2 argument case
|
|
210
|
|
211 template <class _Rp, class _A1, class _A2>
|
|
212 struct __weak_result_type<_Rp (_A1, _A2)>
|
|
213 : public binary_function<_A1, _A2, _Rp>
|
|
214 {
|
|
215 };
|
|
216
|
|
217 template <class _Rp, class _A1, class _A2>
|
|
218 struct __weak_result_type<_Rp (*)(_A1, _A2)>
|
|
219 : public binary_function<_A1, _A2, _Rp>
|
|
220 {
|
|
221 };
|
|
222
|
|
223 template <class _Rp, class _A1, class _A2>
|
|
224 struct __weak_result_type<_Rp (&)(_A1, _A2)>
|
|
225 : public binary_function<_A1, _A2, _Rp>
|
|
226 {
|
|
227 };
|
|
228
|
|
229 template <class _Rp, class _Cp, class _A1>
|
|
230 struct __weak_result_type<_Rp (_Cp::*)(_A1)>
|
|
231 : public binary_function<_Cp*, _A1, _Rp>
|
|
232 {
|
|
233 };
|
|
234
|
|
235 template <class _Rp, class _Cp, class _A1>
|
|
236 struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
|
|
237 : public binary_function<const _Cp*, _A1, _Rp>
|
|
238 {
|
|
239 };
|
|
240
|
|
241 template <class _Rp, class _Cp, class _A1>
|
|
242 struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
|
|
243 : public binary_function<volatile _Cp*, _A1, _Rp>
|
|
244 {
|
|
245 };
|
|
246
|
|
247 template <class _Rp, class _Cp, class _A1>
|
|
248 struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
|
|
249 : public binary_function<const volatile _Cp*, _A1, _Rp>
|
|
250 {
|
|
251 };
|
|
252
|
|
253
|
|
254 #ifndef _LIBCPP_CXX03_LANG
|
|
255 // 3 or more arguments
|
|
256
|
|
257 template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
|
|
258 struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
|
|
259 {
|
|
260 typedef _Rp result_type;
|
|
261 };
|
|
262
|
|
263 template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
|
|
264 struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
|
|
265 {
|
|
266 typedef _Rp result_type;
|
|
267 };
|
|
268
|
|
269 template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
|
|
270 struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
|
|
271 {
|
|
272 typedef _Rp result_type;
|
|
273 };
|
|
274
|
|
275 template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
|
|
276 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
|
|
277 {
|
|
278 typedef _Rp result_type;
|
|
279 };
|
|
280
|
|
281 template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
|
|
282 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
|
|
283 {
|
|
284 typedef _Rp result_type;
|
|
285 };
|
|
286
|
|
287 template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
|
|
288 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
|
|
289 {
|
|
290 typedef _Rp result_type;
|
|
291 };
|
|
292
|
|
293 template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
|
|
294 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
|
|
295 {
|
|
296 typedef _Rp result_type;
|
|
297 };
|
|
298
|
|
299 template <class _Tp, class ..._Args>
|
|
300 struct __invoke_return
|
|
301 {
|
221
|
302 typedef decltype(_VSTD::__invoke(declval<_Tp>(), declval<_Args>()...)) type;
|
150
|
303 };
|
|
304
|
|
305 #else // defined(_LIBCPP_CXX03_LANG)
|
|
306
|
|
307 #include <__functional_base_03>
|
|
308
|
221
|
309 #endif // !defined(_LIBCPP_CXX03_LANG)
|
150
|
310
|
|
311
|
221
|
312 template <class _Ret, bool = is_void<_Ret>::value>
|
150
|
313 struct __invoke_void_return_wrapper
|
|
314 {
|
|
315 #ifndef _LIBCPP_CXX03_LANG
|
|
316 template <class ..._Args>
|
|
317 static _Ret __call(_Args&&... __args) {
|
221
|
318 return _VSTD::__invoke(_VSTD::forward<_Args>(__args)...);
|
150
|
319 }
|
|
320 #else
|
|
321 template <class _Fn>
|
|
322 static _Ret __call(_Fn __f) {
|
221
|
323 return _VSTD::__invoke(__f);
|
150
|
324 }
|
|
325
|
|
326 template <class _Fn, class _A0>
|
|
327 static _Ret __call(_Fn __f, _A0& __a0) {
|
221
|
328 return _VSTD::__invoke(__f, __a0);
|
150
|
329 }
|
|
330
|
|
331 template <class _Fn, class _A0, class _A1>
|
|
332 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
|
221
|
333 return _VSTD::__invoke(__f, __a0, __a1);
|
150
|
334 }
|
|
335
|
|
336 template <class _Fn, class _A0, class _A1, class _A2>
|
|
337 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
|
221
|
338 return _VSTD::__invoke(__f, __a0, __a1, __a2);
|
150
|
339 }
|
|
340 #endif
|
|
341 };
|
|
342
|
221
|
343 template <class _Ret>
|
|
344 struct __invoke_void_return_wrapper<_Ret, true>
|
150
|
345 {
|
|
346 #ifndef _LIBCPP_CXX03_LANG
|
|
347 template <class ..._Args>
|
|
348 static void __call(_Args&&... __args) {
|
221
|
349 _VSTD::__invoke(_VSTD::forward<_Args>(__args)...);
|
150
|
350 }
|
|
351 #else
|
|
352 template <class _Fn>
|
|
353 static void __call(_Fn __f) {
|
221
|
354 _VSTD::__invoke(__f);
|
150
|
355 }
|
|
356
|
|
357 template <class _Fn, class _A0>
|
|
358 static void __call(_Fn __f, _A0& __a0) {
|
221
|
359 _VSTD::__invoke(__f, __a0);
|
150
|
360 }
|
|
361
|
|
362 template <class _Fn, class _A0, class _A1>
|
|
363 static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
|
221
|
364 _VSTD::__invoke(__f, __a0, __a1);
|
150
|
365 }
|
|
366
|
|
367 template <class _Fn, class _A0, class _A1, class _A2>
|
|
368 static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
|
221
|
369 _VSTD::__invoke(__f, __a0, __a1, __a2);
|
150
|
370 }
|
|
371 #endif
|
|
372 };
|
|
373
|
|
374 template <class _Tp>
|
|
375 class _LIBCPP_TEMPLATE_VIS reference_wrapper
|
|
376 : public __weak_result_type<_Tp>
|
|
377 {
|
|
378 public:
|
|
379 // types
|
|
380 typedef _Tp type;
|
|
381 private:
|
|
382 type* __f_;
|
|
383
|
221
|
384 #ifndef _LIBCPP_CXX03_LANG
|
|
385 static void __fun(_Tp&) _NOEXCEPT;
|
|
386 static void __fun(_Tp&&) = delete;
|
|
387 #endif
|
|
388
|
150
|
389 public:
|
|
390 // construct/copy/destroy
|
221
|
391 #ifdef _LIBCPP_CXX03_LANG
|
|
392 _LIBCPP_INLINE_VISIBILITY
|
|
393 reference_wrapper(type& __f) _NOEXCEPT
|
150
|
394 : __f_(_VSTD::addressof(__f)) {}
|
221
|
395 #else
|
|
396 template <class _Up, class = _EnableIf<!__is_same_uncvref<_Up, reference_wrapper>::value, decltype(__fun(declval<_Up>())) >>
|
|
397 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
398 reference_wrapper(_Up&& __u) _NOEXCEPT_(noexcept(__fun(declval<_Up>()))) {
|
|
399 type& __f = static_cast<_Up&&>(__u);
|
|
400 __f_ = _VSTD::addressof(__f);
|
|
401 }
|
150
|
402 #endif
|
|
403
|
|
404 // access
|
221
|
405 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
406 operator type&() const _NOEXCEPT {return *__f_;}
|
|
407 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
|
408 type& get() const _NOEXCEPT {return *__f_;}
|
150
|
409
|
|
410 #ifndef _LIBCPP_CXX03_LANG
|
|
411 // invoke
|
|
412 template <class... _ArgTypes>
|
221
|
413 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
150
|
414 typename __invoke_of<type&, _ArgTypes...>::type
|
|
415 operator() (_ArgTypes&&... __args) const {
|
221
|
416 return _VSTD::__invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
|
150
|
417 }
|
|
418 #else
|
|
419
|
|
420 _LIBCPP_INLINE_VISIBILITY
|
|
421 typename __invoke_return<type>::type
|
|
422 operator() () const {
|
221
|
423 return _VSTD::__invoke(get());
|
150
|
424 }
|
|
425
|
|
426 template <class _A0>
|
|
427 _LIBCPP_INLINE_VISIBILITY
|
|
428 typename __invoke_return0<type, _A0>::type
|
|
429 operator() (_A0& __a0) const {
|
221
|
430 return _VSTD::__invoke(get(), __a0);
|
150
|
431 }
|
|
432
|
|
433 template <class _A0>
|
|
434 _LIBCPP_INLINE_VISIBILITY
|
|
435 typename __invoke_return0<type, _A0 const>::type
|
|
436 operator() (_A0 const& __a0) const {
|
221
|
437 return _VSTD::__invoke(get(), __a0);
|
150
|
438 }
|
|
439
|
|
440 template <class _A0, class _A1>
|
|
441 _LIBCPP_INLINE_VISIBILITY
|
|
442 typename __invoke_return1<type, _A0, _A1>::type
|
|
443 operator() (_A0& __a0, _A1& __a1) const {
|
221
|
444 return _VSTD::__invoke(get(), __a0, __a1);
|
150
|
445 }
|
|
446
|
|
447 template <class _A0, class _A1>
|
|
448 _LIBCPP_INLINE_VISIBILITY
|
|
449 typename __invoke_return1<type, _A0 const, _A1>::type
|
|
450 operator() (_A0 const& __a0, _A1& __a1) const {
|
221
|
451 return _VSTD::__invoke(get(), __a0, __a1);
|
150
|
452 }
|
|
453
|
|
454 template <class _A0, class _A1>
|
|
455 _LIBCPP_INLINE_VISIBILITY
|
|
456 typename __invoke_return1<type, _A0, _A1 const>::type
|
|
457 operator() (_A0& __a0, _A1 const& __a1) const {
|
221
|
458 return _VSTD::__invoke(get(), __a0, __a1);
|
150
|
459 }
|
|
460
|
|
461 template <class _A0, class _A1>
|
|
462 _LIBCPP_INLINE_VISIBILITY
|
|
463 typename __invoke_return1<type, _A0 const, _A1 const>::type
|
|
464 operator() (_A0 const& __a0, _A1 const& __a1) const {
|
221
|
465 return _VSTD::__invoke(get(), __a0, __a1);
|
150
|
466 }
|
|
467
|
|
468 template <class _A0, class _A1, class _A2>
|
|
469 _LIBCPP_INLINE_VISIBILITY
|
|
470 typename __invoke_return2<type, _A0, _A1, _A2>::type
|
|
471 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
|
221
|
472 return _VSTD::__invoke(get(), __a0, __a1, __a2);
|
150
|
473 }
|
|
474
|
|
475 template <class _A0, class _A1, class _A2>
|
|
476 _LIBCPP_INLINE_VISIBILITY
|
|
477 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
|
|
478 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
|
221
|
479 return _VSTD::__invoke(get(), __a0, __a1, __a2);
|
150
|
480 }
|
|
481
|
|
482 template <class _A0, class _A1, class _A2>
|
|
483 _LIBCPP_INLINE_VISIBILITY
|
|
484 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
|
|
485 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
|
221
|
486 return _VSTD::__invoke(get(), __a0, __a1, __a2);
|
150
|
487 }
|
|
488
|
|
489 template <class _A0, class _A1, class _A2>
|
|
490 _LIBCPP_INLINE_VISIBILITY
|
|
491 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
|
|
492 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
|
221
|
493 return _VSTD::__invoke(get(), __a0, __a1, __a2);
|
150
|
494 }
|
|
495
|
|
496 template <class _A0, class _A1, class _A2>
|
|
497 _LIBCPP_INLINE_VISIBILITY
|
|
498 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
|
|
499 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
|
221
|
500 return _VSTD::__invoke(get(), __a0, __a1, __a2);
|
150
|
501 }
|
|
502
|
|
503 template <class _A0, class _A1, class _A2>
|
|
504 _LIBCPP_INLINE_VISIBILITY
|
|
505 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
|
|
506 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
|
221
|
507 return _VSTD::__invoke(get(), __a0, __a1, __a2);
|
150
|
508 }
|
|
509
|
|
510 template <class _A0, class _A1, class _A2>
|
|
511 _LIBCPP_INLINE_VISIBILITY
|
|
512 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
|
|
513 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
|
221
|
514 return _VSTD::__invoke(get(), __a0, __a1, __a2);
|
150
|
515 }
|
|
516
|
|
517 template <class _A0, class _A1, class _A2>
|
|
518 _LIBCPP_INLINE_VISIBILITY
|
|
519 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
|
|
520 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
|
221
|
521 return _VSTD::__invoke(get(), __a0, __a1, __a2);
|
150
|
522 }
|
|
523 #endif // _LIBCPP_CXX03_LANG
|
|
524 };
|
|
525
|
221
|
526 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
|
|
527 template <class _Tp>
|
|
528 reference_wrapper(_Tp&) -> reference_wrapper<_Tp>;
|
|
529 #endif
|
150
|
530
|
|
531 template <class _Tp>
|
221
|
532 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
150
|
533 reference_wrapper<_Tp>
|
|
534 ref(_Tp& __t) _NOEXCEPT
|
|
535 {
|
|
536 return reference_wrapper<_Tp>(__t);
|
|
537 }
|
|
538
|
|
539 template <class _Tp>
|
221
|
540 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
150
|
541 reference_wrapper<_Tp>
|
|
542 ref(reference_wrapper<_Tp> __t) _NOEXCEPT
|
|
543 {
|
173
|
544 return _VSTD::ref(__t.get());
|
150
|
545 }
|
|
546
|
|
547 template <class _Tp>
|
221
|
548 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
150
|
549 reference_wrapper<const _Tp>
|
|
550 cref(const _Tp& __t) _NOEXCEPT
|
|
551 {
|
|
552 return reference_wrapper<const _Tp>(__t);
|
|
553 }
|
|
554
|
|
555 template <class _Tp>
|
221
|
556 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
|
150
|
557 reference_wrapper<const _Tp>
|
|
558 cref(reference_wrapper<_Tp> __t) _NOEXCEPT
|
|
559 {
|
173
|
560 return _VSTD::cref(__t.get());
|
150
|
561 }
|
|
562
|
|
563 #ifndef _LIBCPP_CXX03_LANG
|
|
564 template <class _Tp> void ref(const _Tp&&) = delete;
|
|
565 template <class _Tp> void cref(const _Tp&&) = delete;
|
|
566 #endif
|
|
567
|
|
568 #if _LIBCPP_STD_VER > 11
|
|
569 template <class _Tp, class, class = void>
|
|
570 struct __is_transparent : false_type {};
|
|
571
|
|
572 template <class _Tp, class _Up>
|
|
573 struct __is_transparent<_Tp, _Up,
|
|
574 typename __void_t<typename _Tp::is_transparent>::type>
|
|
575 : true_type {};
|
|
576 #endif
|
|
577
|
|
578 // allocator_arg_t
|
|
579
|
|
580 struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; };
|
|
581
|
|
582 #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
|
|
583 extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;
|
|
584 #else
|
|
585 /* _LIBCPP_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
|
|
586 #endif
|
|
587
|
|
588 // uses_allocator
|
|
589
|
|
590 template <class _Tp>
|
|
591 struct __has_allocator_type
|
|
592 {
|
|
593 private:
|
|
594 struct __two {char __lx; char __lxx;};
|
|
595 template <class _Up> static __two __test(...);
|
|
596 template <class _Up> static char __test(typename _Up::allocator_type* = 0);
|
|
597 public:
|
|
598 static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
|
599 };
|
|
600
|
|
601 template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
|
|
602 struct __uses_allocator
|
|
603 : public integral_constant<bool,
|
|
604 is_convertible<_Alloc, typename _Tp::allocator_type>::value>
|
|
605 {
|
|
606 };
|
|
607
|
|
608 template <class _Tp, class _Alloc>
|
|
609 struct __uses_allocator<_Tp, _Alloc, false>
|
|
610 : public false_type
|
|
611 {
|
|
612 };
|
|
613
|
|
614 template <class _Tp, class _Alloc>
|
|
615 struct _LIBCPP_TEMPLATE_VIS uses_allocator
|
|
616 : public __uses_allocator<_Tp, _Alloc>
|
|
617 {
|
|
618 };
|
|
619
|
|
620 #if _LIBCPP_STD_VER > 14
|
|
621 template <class _Tp, class _Alloc>
|
|
622 _LIBCPP_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
|
|
623 #endif
|
|
624
|
|
625 #ifndef _LIBCPP_CXX03_LANG
|
|
626
|
|
627 // allocator construction
|
|
628
|
|
629 template <class _Tp, class _Alloc, class ..._Args>
|
|
630 struct __uses_alloc_ctor_imp
|
|
631 {
|
|
632 typedef _LIBCPP_NODEBUG_TYPE typename __uncvref<_Alloc>::type _RawAlloc;
|
|
633 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;
|
|
634 static const bool __ic =
|
|
635 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
|
|
636 static const int value = __ua ? 2 - __ic : 0;
|
|
637 };
|
|
638
|
|
639 template <class _Tp, class _Alloc, class ..._Args>
|
|
640 struct __uses_alloc_ctor
|
|
641 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
|
|
642 {};
|
|
643
|
|
644 template <class _Tp, class _Allocator, class... _Args>
|
|
645 inline _LIBCPP_INLINE_VISIBILITY
|
|
646 void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
|
|
647 {
|
|
648 new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
|
|
649 }
|
|
650
|
|
651 // FIXME: This should have a version which takes a non-const alloc.
|
|
652 template <class _Tp, class _Allocator, class... _Args>
|
|
653 inline _LIBCPP_INLINE_VISIBILITY
|
|
654 void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
|
|
655 {
|
|
656 new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
|
|
657 }
|
|
658
|
|
659 // FIXME: This should have a version which takes a non-const alloc.
|
|
660 template <class _Tp, class _Allocator, class... _Args>
|
|
661 inline _LIBCPP_INLINE_VISIBILITY
|
|
662 void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
|
|
663 {
|
|
664 new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
|
|
665 }
|
|
666
|
221
|
667 #endif // _LIBCPP_CXX03_LANG
|
|
668
|
|
669 #if _LIBCPP_STD_VER > 14
|
|
670
|
|
671 template <class _Fn, class ..._Args>
|
|
672 _LIBCPP_CONSTEXPR_AFTER_CXX17 invoke_result_t<_Fn, _Args...>
|
|
673 invoke(_Fn&& __f, _Args&&... __args)
|
|
674 noexcept(is_nothrow_invocable_v<_Fn, _Args...>)
|
|
675 {
|
|
676 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
|
|
677 }
|
|
678
|
|
679 #endif // _LIBCPP_STD_VER > 14
|
150
|
680
|
|
681 _LIBCPP_END_NAMESPACE_STD
|
|
682
|
221
|
683 #endif // _LIBCPP_FUNCTIONAL_BASE
|