blob: 4e2b7eb8d2893c4853959cf45bfbb9bf1eabdea4 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL_BASE
12#define _LIBCPP_FUNCTIONAL_BASE
13
14#include <__config>
15#include <type_traits>
16#include <typeinfo>
17#include <exception>
Marshall Clow599e60d2013-09-12 02:11:1618#include <new>
Eric Fiselier952eaec2017-01-21 00:02:1219#include <utility>
Howard Hinnantbc8d3f92010-05-11 19:42:1620
Howard Hinnant08e17472011-10-17 20:05:1021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:1622#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:1023#endif
Howard Hinnantbc8d3f92010-05-11 19:42:1624
25_LIBCPP_BEGIN_NAMESPACE_STD
26
Howard Hinnantbc8d3f92010-05-11 19:42:1627template <class _Arg1, class _Arg2, class _Result>
Eric Fiselierc3589a82017-01-04 23:56:0028struct _LIBCPP_TEMPLATE_VIS binary_function
Howard Hinnantbc8d3f92010-05-11 19:42:1629{
30 typedef _Arg1 first_argument_type;
31 typedef _Arg2 second_argument_type;
32 typedef _Result result_type;
33};
34
Howard Hinnantbc8d3f92010-05-11 19:42:1635template <class _Tp>
36struct __has_result_type
37{
38private:
Howard Hinnant9c0df142012-10-30 19:06:5939 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:1640 template <class _Up> static __two __test(...);
41 template <class _Up> static char __test(typename _Up::result_type* = 0);
42public:
43 static const bool value = sizeof(__test<_Tp>(0)) == 1;
44};
45
Marshall Clowff464092013-07-29 14:21:5346#if _LIBCPP_STD_VER > 11
47template <class _Tp = void>
48#else
Howard Hinnant3fadda32012-02-21 21:02:5849template <class _Tp>
Marshall Clowff464092013-07-29 14:21:5350#endif
Eric Fiselierc3589a82017-01-04 23:56:0051struct _LIBCPP_TEMPLATE_VIS less : binary_function<_Tp, _Tp, bool>
Howard Hinnant3fadda32012-02-21 21:02:5852{
Marshall Clow9738caf2013-09-28 19:06:1253 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
54 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnant3fadda32012-02-21 21:02:5855 {return __x < __y;}
56};
57
Marshall Clowff464092013-07-29 14:21:5358#if _LIBCPP_STD_VER > 11
59template <>
Eric Fiselierc3589a82017-01-04 23:56:0060struct _LIBCPP_TEMPLATE_VIS less<void>
Marshall Clowff464092013-07-29 14:21:5361{
Marshall Clow9738caf2013-09-28 19:06:1262 template <class _T1, class _T2>
63 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:5364 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:5265 _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); }
Marshall Clow4a0a9812013-08-13 01:11:0668 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:5369};
70#endif
71
Howard Hinnantbc8d3f92010-05-11 19:42:1672// __weak_result_type
73
74template <class _Tp>
75struct __derives_from_unary_function
76{
77private:
Howard Hinnant9c0df142012-10-30 19:06:5978 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:1679 static __two __test(...);
Howard Hinnant99968442011-11-29 18:15:5080 template <class _Ap, class _Rp>
81 static unary_function<_Ap, _Rp>
82 __test(const volatile unary_function<_Ap, _Rp>*);
Howard Hinnantbc8d3f92010-05-11 19:42:1683public:
84 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
85 typedef decltype(__test((_Tp*)0)) type;
86};
87
88template <class _Tp>
89struct __derives_from_binary_function
90{
91private:
Howard Hinnant9c0df142012-10-30 19:06:5992 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:1693 static __two __test(...);
Howard Hinnant99968442011-11-29 18:15:5094 template <class _A1, class _A2, class _Rp>
95 static binary_function<_A1, _A2, _Rp>
96 __test(const volatile binary_function<_A1, _A2, _Rp>*);
Howard Hinnantbc8d3f92010-05-11 19:42:1697public:
98 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
99 typedef decltype(__test((_Tp*)0)) type;
100};
101
102template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
103struct __maybe_derive_from_unary_function // bool is true
104 : public __derives_from_unary_function<_Tp>::type
105{
106};
107
108template <class _Tp>
109struct __maybe_derive_from_unary_function<_Tp, false>
110{
111};
112
113template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
114struct __maybe_derive_from_binary_function // bool is true
115 : public __derives_from_binary_function<_Tp>::type
116{
117};
118
119template <class _Tp>
120struct __maybe_derive_from_binary_function<_Tp, false>
121{
122};
123
124template <class _Tp, bool = __has_result_type<_Tp>::value>
125struct __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 typename _Tp::result_type result_type;
130};
131
132template <class _Tp>
133struct __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
139template <class _Tp>
140struct __weak_result_type
141 : public __weak_result_type_imp<_Tp>
142{
143};
144
145// 0 argument case
146
Howard Hinnant99968442011-11-29 18:15:50147template <class _Rp>
148struct __weak_result_type<_Rp ()>
Howard Hinnantbc8d3f92010-05-11 19:42:16149{
Howard Hinnant99968442011-11-29 18:15:50150 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16151};
152
Howard Hinnant99968442011-11-29 18:15:50153template <class _Rp>
154struct __weak_result_type<_Rp (&)()>
Howard Hinnantbc8d3f92010-05-11 19:42:16155{
Howard Hinnant99968442011-11-29 18:15:50156 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16157};
158
Howard Hinnant99968442011-11-29 18:15:50159template <class _Rp>
160struct __weak_result_type<_Rp (*)()>
Howard Hinnantbc8d3f92010-05-11 19:42:16161{
Howard Hinnant99968442011-11-29 18:15:50162 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16163};
164
165// 1 argument case
166
Howard Hinnant99968442011-11-29 18:15:50167template <class _Rp, class _A1>
168struct __weak_result_type<_Rp (_A1)>
169 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16170{
171};
172
Howard Hinnant99968442011-11-29 18:15:50173template <class _Rp, class _A1>
174struct __weak_result_type<_Rp (&)(_A1)>
175 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16176{
177};
178
Howard Hinnant99968442011-11-29 18:15:50179template <class _Rp, class _A1>
180struct __weak_result_type<_Rp (*)(_A1)>
181 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16182{
183};
184
Howard Hinnant99968442011-11-29 18:15:50185template <class _Rp, class _Cp>
186struct __weak_result_type<_Rp (_Cp::*)()>
187 : public unary_function<_Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16188{
189};
190
Howard Hinnant99968442011-11-29 18:15:50191template <class _Rp, class _Cp>
192struct __weak_result_type<_Rp (_Cp::*)() const>
193 : public unary_function<const _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16194{
195};
196
Howard Hinnant99968442011-11-29 18:15:50197template <class _Rp, class _Cp>
198struct __weak_result_type<_Rp (_Cp::*)() volatile>
199 : public unary_function<volatile _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16200{
201};
202
Howard Hinnant99968442011-11-29 18:15:50203template <class _Rp, class _Cp>
204struct __weak_result_type<_Rp (_Cp::*)() const volatile>
205 : public unary_function<const volatile _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16206{
207};
208
209// 2 argument case
210
Howard Hinnant99968442011-11-29 18:15:50211template <class _Rp, class _A1, class _A2>
212struct __weak_result_type<_Rp (_A1, _A2)>
213 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16214{
215};
216
Howard Hinnant99968442011-11-29 18:15:50217template <class _Rp, class _A1, class _A2>
218struct __weak_result_type<_Rp (*)(_A1, _A2)>
219 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16220{
221};
222
Howard Hinnant99968442011-11-29 18:15:50223template <class _Rp, class _A1, class _A2>
224struct __weak_result_type<_Rp (&)(_A1, _A2)>
225 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16226{
227};
228
Howard Hinnant99968442011-11-29 18:15:50229template <class _Rp, class _Cp, class _A1>
230struct __weak_result_type<_Rp (_Cp::*)(_A1)>
231 : public binary_function<_Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16232{
233};
234
Howard Hinnant99968442011-11-29 18:15:50235template <class _Rp, class _Cp, class _A1>
236struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
237 : public binary_function<const _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16238{
239};
240
Howard Hinnant99968442011-11-29 18:15:50241template <class _Rp, class _Cp, class _A1>
242struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
243 : public binary_function<volatile _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16244{
245};
246
Howard Hinnant99968442011-11-29 18:15:50247template <class _Rp, class _Cp, class _A1>
248struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
249 : public binary_function<const volatile _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16250{
251};
252
Eric Fiselier5b3a4592015-07-22 22:23:49253
254#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16255// 3 or more arguments
256
Howard Hinnant99968442011-11-29 18:15:50257template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
258struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16259{
Howard Hinnant99968442011-11-29 18:15:50260 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16261};
262
Howard Hinnant99968442011-11-29 18:15:50263template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
264struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16265{
Howard Hinnant99968442011-11-29 18:15:50266 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16267};
268
Howard Hinnant99968442011-11-29 18:15:50269template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
270struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16271{
Howard Hinnant99968442011-11-29 18:15:50272 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16273};
274
Howard Hinnant99968442011-11-29 18:15:50275template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
276struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16277{
Howard Hinnant99968442011-11-29 18:15:50278 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16279};
280
Howard Hinnant99968442011-11-29 18:15:50281template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
282struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
Howard Hinnantbc8d3f92010-05-11 19:42:16283{
Howard Hinnant99968442011-11-29 18:15:50284 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16285};
286
Howard Hinnant99968442011-11-29 18:15:50287template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
288struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
Howard Hinnantbc8d3f92010-05-11 19:42:16289{
Howard Hinnant99968442011-11-29 18:15:50290 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16291};
292
Howard Hinnant99968442011-11-29 18:15:50293template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
294struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
Howard Hinnantbc8d3f92010-05-11 19:42:16295{
Howard Hinnant99968442011-11-29 18:15:50296 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16297};
298
Eric Fiselier5b3a4592015-07-22 22:23:49299#endif // _LIBCPP_HAS_NO_VARIADICS
300
Eric Fiselier8d5cbd72016-04-20 00:14:32301#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16302
Howard Hinnantbc8d3f92010-05-11 19:42:16303template <class _Tp, class ..._Args>
304struct __invoke_return
305{
Howard Hinnant0949eed2011-06-30 21:18:19306 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
Howard Hinnantbc8d3f92010-05-11 19:42:16307};
308
Eric Fiselier8d5cbd72016-04-20 00:14:32309#else // defined(_LIBCPP_CXX03_LANG)
Eric Fiselier5b3a4592015-07-22 22:23:49310
311#include <__functional_base_03>
312
Eric Fiselier8d5cbd72016-04-20 00:14:32313#endif // !defined(_LIBCPP_CXX03_LANG)
Eric Fiselier5b3a4592015-07-22 22:23:49314
315
Eric Fiselierc3231d22015-02-10 16:48:45316template <class _Ret>
317struct __invoke_void_return_wrapper
318{
Eric Fiselier5b3a4592015-07-22 22:23:49319#ifndef _LIBCPP_HAS_NO_VARIADICS
Eric Fiselierc3231d22015-02-10 16:48:45320 template <class ..._Args>
Eric Fiselier5b3a4592015-07-22 22:23:49321 static _Ret __call(_Args&&... __args) {
Eric Fiselierc3231d22015-02-10 16:48:45322 return __invoke(_VSTD::forward<_Args>(__args)...);
323 }
Eric Fiselier5b3a4592015-07-22 22:23:49324#else
325 template <class _Fn>
326 static _Ret __call(_Fn __f) {
327 return __invoke(__f);
328 }
329
330 template <class _Fn, class _A0>
331 static _Ret __call(_Fn __f, _A0& __a0) {
332 return __invoke(__f, __a0);
333 }
334
335 template <class _Fn, class _A0, class _A1>
336 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
337 return __invoke(__f, __a0, __a1);
338 }
339
340 template <class _Fn, class _A0, class _A1, class _A2>
341 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
342 return __invoke(__f, __a0, __a1, __a2);
343 }
344#endif
Eric Fiselierc3231d22015-02-10 16:48:45345};
346
347template <>
348struct __invoke_void_return_wrapper<void>
349{
Eric Fiselier5b3a4592015-07-22 22:23:49350#ifndef _LIBCPP_HAS_NO_VARIADICS
Eric Fiselierc3231d22015-02-10 16:48:45351 template <class ..._Args>
Eric Fiselier5b3a4592015-07-22 22:23:49352 static void __call(_Args&&... __args) {
Eric Fiselierc3231d22015-02-10 16:48:45353 __invoke(_VSTD::forward<_Args>(__args)...);
354 }
Eric Fiselier5b3a4592015-07-22 22:23:49355#else
356 template <class _Fn>
357 static void __call(_Fn __f) {
358 __invoke(__f);
359 }
360
361 template <class _Fn, class _A0>
362 static void __call(_Fn __f, _A0& __a0) {
363 __invoke(__f, __a0);
364 }
365
366 template <class _Fn, class _A0, class _A1>
367 static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
368 __invoke(__f, __a0, __a1);
369 }
370
371 template <class _Fn, class _A0, class _A1, class _A2>
372 static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
373 __invoke(__f, __a0, __a1, __a2);
374 }
375#endif
Eric Fiselierc3231d22015-02-10 16:48:45376};
377
Howard Hinnantbc8d3f92010-05-11 19:42:16378template <class _Tp>
Eric Fiselierc3589a82017-01-04 23:56:00379class _LIBCPP_TEMPLATE_VIS reference_wrapper
Howard Hinnantbc8d3f92010-05-11 19:42:16380 : public __weak_result_type<_Tp>
381{
382public:
383 // types
384 typedef _Tp type;
385private:
386 type* __f_;
387
388public:
389 // construct/copy/destroy
Howard Hinnanta4e87ab2013-08-08 18:38:55390 _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
391 : __f_(_VSTD::addressof(__f)) {}
Howard Hinnant73d21a42010-09-04 23:28:19392#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16393 private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
394#endif
395
396 // access
Howard Hinnant603d2c02011-05-28 17:59:48397 _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;}
398 _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16399
Eric Fiselier5b3a4592015-07-22 22:23:49400#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16401 // invoke
402 template <class... _ArgTypes>
Eric Fiselierf1626ad2015-08-26 20:15:02403 _LIBCPP_INLINE_VISIBILITY
404 typename __invoke_of<type&, _ArgTypes...>::type
405 operator() (_ArgTypes&&... __args) const {
406 return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
407 }
Eric Fiselier5b3a4592015-07-22 22:23:49408#else
409
410 _LIBCPP_INLINE_VISIBILITY
411 typename __invoke_return<type>::type
Eric Fiselierf1626ad2015-08-26 20:15:02412 operator() () const {
413 return __invoke(get());
414 }
Eric Fiselier5b3a4592015-07-22 22:23:49415
416 template <class _A0>
Eric Fiselierf1626ad2015-08-26 20:15:02417 _LIBCPP_INLINE_VISIBILITY
418 typename __invoke_return0<type, _A0>::type
419 operator() (_A0& __a0) const {
420 return __invoke(get(), __a0);
421 }
422
423 template <class _A0>
424 _LIBCPP_INLINE_VISIBILITY
425 typename __invoke_return0<type, _A0 const>::type
426 operator() (_A0 const& __a0) const {
427 return __invoke(get(), __a0);
428 }
Eric Fiselier5b3a4592015-07-22 22:23:49429
430 template <class _A0, class _A1>
Eric Fiselierf1626ad2015-08-26 20:15:02431 _LIBCPP_INLINE_VISIBILITY
432 typename __invoke_return1<type, _A0, _A1>::type
433 operator() (_A0& __a0, _A1& __a1) const {
434 return __invoke(get(), __a0, __a1);
435 }
436
437 template <class _A0, class _A1>
438 _LIBCPP_INLINE_VISIBILITY
439 typename __invoke_return1<type, _A0 const, _A1>::type
440 operator() (_A0 const& __a0, _A1& __a1) const {
441 return __invoke(get(), __a0, __a1);
442 }
443
444 template <class _A0, class _A1>
445 _LIBCPP_INLINE_VISIBILITY
446 typename __invoke_return1<type, _A0, _A1 const>::type
447 operator() (_A0& __a0, _A1 const& __a1) const {
448 return __invoke(get(), __a0, __a1);
449 }
450
451 template <class _A0, class _A1>
452 _LIBCPP_INLINE_VISIBILITY
453 typename __invoke_return1<type, _A0 const, _A1 const>::type
454 operator() (_A0 const& __a0, _A1 const& __a1) const {
455 return __invoke(get(), __a0, __a1);
456 }
Eric Fiselier5b3a4592015-07-22 22:23:49457
458 template <class _A0, class _A1, class _A2>
Eric Fiselierf1626ad2015-08-26 20:15:02459 _LIBCPP_INLINE_VISIBILITY
460 typename __invoke_return2<type, _A0, _A1, _A2>::type
461 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
462 return __invoke(get(), __a0, __a1, __a2);
463 }
464
465 template <class _A0, class _A1, class _A2>
466 _LIBCPP_INLINE_VISIBILITY
467 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
468 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
469 return __invoke(get(), __a0, __a1, __a2);
470 }
471
472 template <class _A0, class _A1, class _A2>
473 _LIBCPP_INLINE_VISIBILITY
474 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
475 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
476 return __invoke(get(), __a0, __a1, __a2);
477 }
478
479 template <class _A0, class _A1, class _A2>
480 _LIBCPP_INLINE_VISIBILITY
481 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
482 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
483 return __invoke(get(), __a0, __a1, __a2);
484 }
485
486 template <class _A0, class _A1, class _A2>
487 _LIBCPP_INLINE_VISIBILITY
488 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
489 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
490 return __invoke(get(), __a0, __a1, __a2);
491 }
492
493 template <class _A0, class _A1, class _A2>
494 _LIBCPP_INLINE_VISIBILITY
495 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
496 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
497 return __invoke(get(), __a0, __a1, __a2);
498 }
499
500 template <class _A0, class _A1, class _A2>
501 _LIBCPP_INLINE_VISIBILITY
502 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
503 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
504 return __invoke(get(), __a0, __a1, __a2);
505 }
506
507 template <class _A0, class _A1, class _A2>
508 _LIBCPP_INLINE_VISIBILITY
509 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
510 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
511 return __invoke(get(), __a0, __a1, __a2);
512 }
Eric Fiselier5b3a4592015-07-22 22:23:49513#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16514};
515
Howard Hinnantbc8d3f92010-05-11 19:42:16516
517template <class _Tp>
518inline _LIBCPP_INLINE_VISIBILITY
519reference_wrapper<_Tp>
Howard Hinnant603d2c02011-05-28 17:59:48520ref(_Tp& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16521{
522 return reference_wrapper<_Tp>(__t);
523}
524
525template <class _Tp>
526inline _LIBCPP_INLINE_VISIBILITY
527reference_wrapper<_Tp>
Howard Hinnant603d2c02011-05-28 17:59:48528ref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16529{
530 return ref(__t.get());
531}
532
533template <class _Tp>
534inline _LIBCPP_INLINE_VISIBILITY
535reference_wrapper<const _Tp>
Howard Hinnant603d2c02011-05-28 17:59:48536cref(const _Tp& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16537{
538 return reference_wrapper<const _Tp>(__t);
539}
540
541template <class _Tp>
542inline _LIBCPP_INLINE_VISIBILITY
543reference_wrapper<const _Tp>
Howard Hinnant603d2c02011-05-28 17:59:48544cref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16545{
546 return cref(__t.get());
547}
548
Eric Fiselier8eb066a2017-01-06 20:58:25549#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantec3773c2011-12-01 20:21:04550template <class _Tp> void ref(const _Tp&&) = delete;
551template <class _Tp> void cref(const _Tp&&) = delete;
Eric Fiselier8eb066a2017-01-06 20:58:25552#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16553
Marshall Clow4a0a9812013-08-13 01:11:06554#if _LIBCPP_STD_VER > 11
555template <class _Tp1, class _Tp2 = void>
556struct __is_transparent
557{
558private:
559 struct __two {char __lx; char __lxx;};
560 template <class _Up> static __two __test(...);
561 template <class _Up> static char __test(typename _Up::is_transparent* = 0);
562public:
563 static const bool value = sizeof(__test<_Tp1>(0)) == 1;
564};
565#endif
566
Marshall Clow599e60d2013-09-12 02:11:16567// allocator_arg_t
568
Eric Fiselierc3589a82017-01-04 23:56:00569struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { };
Marshall Clow599e60d2013-09-12 02:11:16570
571#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY)
572extern const allocator_arg_t allocator_arg;
573#else
574constexpr allocator_arg_t allocator_arg = allocator_arg_t();
575#endif
576
577// uses_allocator
578
579template <class _Tp>
580struct __has_allocator_type
581{
582private:
583 struct __two {char __lx; char __lxx;};
584 template <class _Up> static __two __test(...);
585 template <class _Up> static char __test(typename _Up::allocator_type* = 0);
586public:
587 static const bool value = sizeof(__test<_Tp>(0)) == 1;
588};
589
590template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
591struct __uses_allocator
592 : public integral_constant<bool,
593 is_convertible<_Alloc, typename _Tp::allocator_type>::value>
594{
595};
596
597template <class _Tp, class _Alloc>
598struct __uses_allocator<_Tp, _Alloc, false>
599 : public false_type
600{
601};
602
603template <class _Tp, class _Alloc>
Eric Fiselierc3589a82017-01-04 23:56:00604struct _LIBCPP_TEMPLATE_VIS uses_allocator
Marshall Clow599e60d2013-09-12 02:11:16605 : public __uses_allocator<_Tp, _Alloc>
606{
607};
608
Marshall Clow2fffe3a2016-09-22 00:23:15609#if _LIBCPP_STD_VER > 14
610template <class _Tp, class _Alloc>
611constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
612#endif
613
Marshall Clow599e60d2013-09-12 02:11:16614#ifndef _LIBCPP_HAS_NO_VARIADICS
615
616// allocator construction
617
618template <class _Tp, class _Alloc, class ..._Args>
619struct __uses_alloc_ctor_imp
620{
Eric Fiselierff624752016-12-14 21:29:29621 typedef typename __uncvref<_Alloc>::type _RawAlloc;
622 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;
Marshall Clow599e60d2013-09-12 02:11:16623 static const bool __ic =
624 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
625 static const int value = __ua ? 2 - __ic : 0;
626};
627
628template <class _Tp, class _Alloc, class ..._Args>
629struct __uses_alloc_ctor
630 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
631 {};
632
633template <class _Tp, class _Allocator, class... _Args>
634inline _LIBCPP_INLINE_VISIBILITY
635void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
636{
637 new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
638}
639
Eric Fiselierff624752016-12-14 21:29:29640// FIXME: This should have a version which takes a non-const alloc.
Marshall Clow599e60d2013-09-12 02:11:16641template <class _Tp, class _Allocator, class... _Args>
642inline _LIBCPP_INLINE_VISIBILITY
643void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
644{
645 new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
646}
647
Eric Fiselierff624752016-12-14 21:29:29648// FIXME: This should have a version which takes a non-const alloc.
Marshall Clow599e60d2013-09-12 02:11:16649template <class _Tp, class _Allocator, class... _Args>
650inline _LIBCPP_INLINE_VISIBILITY
651void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
652{
653 new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
654}
655
Eric Fiselierff624752016-12-14 21:29:29656// FIXME: Theis should have a version which takes a non-const alloc.
Marshall Clow599e60d2013-09-12 02:11:16657template <class _Tp, class _Allocator, class... _Args>
658inline _LIBCPP_INLINE_VISIBILITY
659void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args)
660{
661 __user_alloc_construct_impl(
662 __uses_alloc_ctor<_Tp, _Allocator>(),
663 __storage, __a, _VSTD::forward<_Args>(__args)...
664 );
665}
666#endif // _LIBCPP_HAS_NO_VARIADICS
Marshall Clow4a0a9812013-08-13 01:11:06667
Howard Hinnantbc8d3f92010-05-11 19:42:16668_LIBCPP_END_NAMESPACE_STD
669
670#endif // _LIBCPP_FUNCTIONAL_BASE