blob: 79017fe759b49b320010fb6c157d7f0679b58c2c [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
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 Clow50c003b2013-09-12 02:11:16 +000018#include <new>
Eric Fiselierf9127592017-01-21 00:02:12 +000019#include <utility>
Howard Hinnant3e519522010-05-11 19:42:16 +000020
Howard Hinnant073458b2011-10-17 20:05:10 +000021#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +000022#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +000023#endif
Howard Hinnant3e519522010-05-11 19:42:16 +000024
25_LIBCPP_BEGIN_NAMESPACE_STD
26
Howard Hinnant3e519522010-05-11 19:42:16 +000027template <class _Arg1, class _Arg2, class _Result>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +000028struct _LIBCPP_TEMPLATE_VIS binary_function
Howard Hinnant3e519522010-05-11 19:42:16 +000029{
30 typedef _Arg1 first_argument_type;
31 typedef _Arg2 second_argument_type;
32 typedef _Result result_type;
33};
34
Howard Hinnant3e519522010-05-11 19:42:16 +000035template <class _Tp>
36struct __has_result_type
37{
38private:
Howard Hinnant54d333a2012-10-30 19:06:59 +000039 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +000040 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 Clow83c08b42013-07-29 14:21:53 +000046#if _LIBCPP_STD_VER > 11
47template <class _Tp = void>
48#else
Howard Hinnant67f39642012-02-21 21:02:58 +000049template <class _Tp>
Marshall Clow83c08b42013-07-29 14:21:53 +000050#endif
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +000051struct _LIBCPP_TEMPLATE_VIS less : binary_function<_Tp, _Tp, bool>
Howard Hinnant67f39642012-02-21 21:02:58 +000052{
Marshall Clow3d5134dd2013-09-28 19:06:12 +000053 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
54 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnant67f39642012-02-21 21:02:58 +000055 {return __x < __y;}
56};
57
Marshall Clow83c08b42013-07-29 14:21:53 +000058#if _LIBCPP_STD_VER > 11
59template <>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +000060struct _LIBCPP_TEMPLATE_VIS less<void>
Marshall Clow83c08b42013-07-29 14:21:53 +000061{
Marshall Clow3d5134dd2013-09-28 19:06:12 +000062 template <class _T1, class _T2>
63 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow83c08b42013-07-29 14:21:53 +000064 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowa64f2fb2015-02-25 12:20:52 +000065 _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 Clow25d34022013-08-13 01:11:06 +000068 typedef void is_transparent;
Marshall Clow83c08b42013-07-29 14:21:53 +000069};
70#endif
71
Howard Hinnant3e519522010-05-11 19:42:16 +000072// __weak_result_type
73
74template <class _Tp>
75struct __derives_from_unary_function
76{
77private:
Howard Hinnant54d333a2012-10-30 19:06:59 +000078 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +000079 static __two __test(...);
Howard Hinnantc003db12011-11-29 18:15:50 +000080 template <class _Ap, class _Rp>
81 static unary_function<_Ap, _Rp>
82 __test(const volatile unary_function<_Ap, _Rp>*);
Howard Hinnant3e519522010-05-11 19:42:16 +000083public:
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 Hinnant54d333a2012-10-30 19:06:59 +000092 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +000093 static __two __test(...);
Howard Hinnantc003db12011-11-29 18:15:50 +000094 template <class _A1, class _A2, class _Rp>
95 static binary_function<_A1, _A2, _Rp>
96 __test(const volatile binary_function<_A1, _A2, _Rp>*);
Howard Hinnant3e519522010-05-11 19:42:16 +000097public:
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 Hinnantc003db12011-11-29 18:15:50 +0000147template <class _Rp>
148struct __weak_result_type<_Rp ()>
Howard Hinnant3e519522010-05-11 19:42:16 +0000149{
Howard Hinnantc003db12011-11-29 18:15:50 +0000150 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000151};
152
Howard Hinnantc003db12011-11-29 18:15:50 +0000153template <class _Rp>
154struct __weak_result_type<_Rp (&)()>
Howard Hinnant3e519522010-05-11 19:42:16 +0000155{
Howard Hinnantc003db12011-11-29 18:15:50 +0000156 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000157};
158
Howard Hinnantc003db12011-11-29 18:15:50 +0000159template <class _Rp>
160struct __weak_result_type<_Rp (*)()>
Howard Hinnant3e519522010-05-11 19:42:16 +0000161{
Howard Hinnantc003db12011-11-29 18:15:50 +0000162 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000163};
164
165// 1 argument case
166
Howard Hinnantc003db12011-11-29 18:15:50 +0000167template <class _Rp, class _A1>
168struct __weak_result_type<_Rp (_A1)>
169 : public unary_function<_A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000170{
171};
172
Howard Hinnantc003db12011-11-29 18:15:50 +0000173template <class _Rp, class _A1>
174struct __weak_result_type<_Rp (&)(_A1)>
175 : public unary_function<_A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000176{
177};
178
Howard Hinnantc003db12011-11-29 18:15:50 +0000179template <class _Rp, class _A1>
180struct __weak_result_type<_Rp (*)(_A1)>
181 : public unary_function<_A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000182{
183};
184
Howard Hinnantc003db12011-11-29 18:15:50 +0000185template <class _Rp, class _Cp>
186struct __weak_result_type<_Rp (_Cp::*)()>
187 : public unary_function<_Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000188{
189};
190
Howard Hinnantc003db12011-11-29 18:15:50 +0000191template <class _Rp, class _Cp>
192struct __weak_result_type<_Rp (_Cp::*)() const>
193 : public unary_function<const _Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000194{
195};
196
Howard Hinnantc003db12011-11-29 18:15:50 +0000197template <class _Rp, class _Cp>
198struct __weak_result_type<_Rp (_Cp::*)() volatile>
199 : public unary_function<volatile _Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000200{
201};
202
Howard Hinnantc003db12011-11-29 18:15:50 +0000203template <class _Rp, class _Cp>
204struct __weak_result_type<_Rp (_Cp::*)() const volatile>
205 : public unary_function<const volatile _Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000206{
207};
208
209// 2 argument case
210
Howard Hinnantc003db12011-11-29 18:15:50 +0000211template <class _Rp, class _A1, class _A2>
212struct __weak_result_type<_Rp (_A1, _A2)>
213 : public binary_function<_A1, _A2, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000214{
215};
216
Howard Hinnantc003db12011-11-29 18:15:50 +0000217template <class _Rp, class _A1, class _A2>
218struct __weak_result_type<_Rp (*)(_A1, _A2)>
219 : public binary_function<_A1, _A2, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000220{
221};
222
Howard Hinnantc003db12011-11-29 18:15:50 +0000223template <class _Rp, class _A1, class _A2>
224struct __weak_result_type<_Rp (&)(_A1, _A2)>
225 : public binary_function<_A1, _A2, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000226{
227};
228
Howard Hinnantc003db12011-11-29 18:15:50 +0000229template <class _Rp, class _Cp, class _A1>
230struct __weak_result_type<_Rp (_Cp::*)(_A1)>
231 : public binary_function<_Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000232{
233};
234
Howard Hinnantc003db12011-11-29 18:15:50 +0000235template <class _Rp, class _Cp, class _A1>
236struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
237 : public binary_function<const _Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000238{
239};
240
Howard Hinnantc003db12011-11-29 18:15:50 +0000241template <class _Rp, class _Cp, class _A1>
242struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
243 : public binary_function<volatile _Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000244{
245};
246
Howard Hinnantc003db12011-11-29 18:15:50 +0000247template <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 Hinnant3e519522010-05-11 19:42:16 +0000250{
251};
252
Eric Fiselier48cf1282015-07-22 22:23:49 +0000253
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000254#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000255// 3 or more arguments
256
Howard Hinnantc003db12011-11-29 18:15:50 +0000257template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
258struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
Howard Hinnant3e519522010-05-11 19:42:16 +0000259{
Howard Hinnantc003db12011-11-29 18:15:50 +0000260 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000261};
262
Howard Hinnantc003db12011-11-29 18:15:50 +0000263template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
264struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
Howard Hinnant3e519522010-05-11 19:42:16 +0000265{
Howard Hinnantc003db12011-11-29 18:15:50 +0000266 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000267};
268
Howard Hinnantc003db12011-11-29 18:15:50 +0000269template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
270struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
Howard Hinnant3e519522010-05-11 19:42:16 +0000271{
Howard Hinnantc003db12011-11-29 18:15:50 +0000272 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000273};
274
Howard Hinnantc003db12011-11-29 18:15:50 +0000275template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
276struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
Howard Hinnant3e519522010-05-11 19:42:16 +0000277{
Howard Hinnantc003db12011-11-29 18:15:50 +0000278 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000279};
280
Howard Hinnantc003db12011-11-29 18:15:50 +0000281template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
282struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
Howard Hinnant3e519522010-05-11 19:42:16 +0000283{
Howard Hinnantc003db12011-11-29 18:15:50 +0000284 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000285};
286
Howard Hinnantc003db12011-11-29 18:15:50 +0000287template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
288struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
Howard Hinnant3e519522010-05-11 19:42:16 +0000289{
Howard Hinnantc003db12011-11-29 18:15:50 +0000290 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000291};
292
Howard Hinnantc003db12011-11-29 18:15:50 +0000293template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
294struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
Howard Hinnant3e519522010-05-11 19:42:16 +0000295{
Howard Hinnantc003db12011-11-29 18:15:50 +0000296 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000297};
298
Howard Hinnant3e519522010-05-11 19:42:16 +0000299template <class _Tp, class ..._Args>
300struct __invoke_return
301{
Howard Hinnantce48a112011-06-30 21:18:19 +0000302 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000303};
304
Eric Fiselier840fa742016-04-20 00:14:32 +0000305#else // defined(_LIBCPP_CXX03_LANG)
Eric Fiselier48cf1282015-07-22 22:23:49 +0000306
307#include <__functional_base_03>
308
Eric Fiselier840fa742016-04-20 00:14:32 +0000309#endif // !defined(_LIBCPP_CXX03_LANG)
Eric Fiselier48cf1282015-07-22 22:23:49 +0000310
311
Eric Fiselier54519a62015-02-10 16:48:45 +0000312template <class _Ret>
313struct __invoke_void_return_wrapper
314{
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000315#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier54519a62015-02-10 16:48:45 +0000316 template <class ..._Args>
Eric Fiselier48cf1282015-07-22 22:23:49 +0000317 static _Ret __call(_Args&&... __args) {
Eric Fiselier54519a62015-02-10 16:48:45 +0000318 return __invoke(_VSTD::forward<_Args>(__args)...);
319 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000320#else
321 template <class _Fn>
322 static _Ret __call(_Fn __f) {
323 return __invoke(__f);
324 }
325
326 template <class _Fn, class _A0>
327 static _Ret __call(_Fn __f, _A0& __a0) {
328 return __invoke(__f, __a0);
329 }
330
331 template <class _Fn, class _A0, class _A1>
332 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
333 return __invoke(__f, __a0, __a1);
334 }
335
336 template <class _Fn, class _A0, class _A1, class _A2>
337 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
338 return __invoke(__f, __a0, __a1, __a2);
339 }
340#endif
Eric Fiselier54519a62015-02-10 16:48:45 +0000341};
342
343template <>
344struct __invoke_void_return_wrapper<void>
345{
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000346#ifndef _LIBCPP_CXX03_LANG
Eric Fiselier54519a62015-02-10 16:48:45 +0000347 template <class ..._Args>
Eric Fiselier48cf1282015-07-22 22:23:49 +0000348 static void __call(_Args&&... __args) {
Eric Fiselier54519a62015-02-10 16:48:45 +0000349 __invoke(_VSTD::forward<_Args>(__args)...);
350 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000351#else
352 template <class _Fn>
353 static void __call(_Fn __f) {
354 __invoke(__f);
355 }
356
357 template <class _Fn, class _A0>
358 static void __call(_Fn __f, _A0& __a0) {
359 __invoke(__f, __a0);
360 }
361
362 template <class _Fn, class _A0, class _A1>
363 static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
364 __invoke(__f, __a0, __a1);
365 }
366
367 template <class _Fn, class _A0, class _A1, class _A2>
368 static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
369 __invoke(__f, __a0, __a1, __a2);
370 }
371#endif
Eric Fiselier54519a62015-02-10 16:48:45 +0000372};
373
Howard Hinnant3e519522010-05-11 19:42:16 +0000374template <class _Tp>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000375class _LIBCPP_TEMPLATE_VIS reference_wrapper
Howard Hinnant3e519522010-05-11 19:42:16 +0000376 : public __weak_result_type<_Tp>
377{
378public:
379 // types
380 typedef _Tp type;
381private:
382 type* __f_;
383
384public:
385 // construct/copy/destroy
Howard Hinnant8c974202013-08-08 18:38:55 +0000386 _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
387 : __f_(_VSTD::addressof(__f)) {}
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000388#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000389 private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
390#endif
391
392 // access
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000393 _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;}
394 _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000395
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000396#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000397 // invoke
398 template <class... _ArgTypes>
Eric Fiselier70192a92015-08-26 20:15:02 +0000399 _LIBCPP_INLINE_VISIBILITY
400 typename __invoke_of<type&, _ArgTypes...>::type
401 operator() (_ArgTypes&&... __args) const {
402 return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
403 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000404#else
405
406 _LIBCPP_INLINE_VISIBILITY
407 typename __invoke_return<type>::type
Eric Fiselier70192a92015-08-26 20:15:02 +0000408 operator() () const {
409 return __invoke(get());
410 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000411
412 template <class _A0>
Eric Fiselier70192a92015-08-26 20:15:02 +0000413 _LIBCPP_INLINE_VISIBILITY
414 typename __invoke_return0<type, _A0>::type
415 operator() (_A0& __a0) const {
416 return __invoke(get(), __a0);
417 }
418
419 template <class _A0>
420 _LIBCPP_INLINE_VISIBILITY
421 typename __invoke_return0<type, _A0 const>::type
422 operator() (_A0 const& __a0) const {
423 return __invoke(get(), __a0);
424 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000425
426 template <class _A0, class _A1>
Eric Fiselier70192a92015-08-26 20:15:02 +0000427 _LIBCPP_INLINE_VISIBILITY
428 typename __invoke_return1<type, _A0, _A1>::type
429 operator() (_A0& __a0, _A1& __a1) const {
430 return __invoke(get(), __a0, __a1);
431 }
432
433 template <class _A0, class _A1>
434 _LIBCPP_INLINE_VISIBILITY
435 typename __invoke_return1<type, _A0 const, _A1>::type
436 operator() (_A0 const& __a0, _A1& __a1) const {
437 return __invoke(get(), __a0, __a1);
438 }
439
440 template <class _A0, class _A1>
441 _LIBCPP_INLINE_VISIBILITY
442 typename __invoke_return1<type, _A0, _A1 const>::type
443 operator() (_A0& __a0, _A1 const& __a1) const {
444 return __invoke(get(), __a0, __a1);
445 }
446
447 template <class _A0, class _A1>
448 _LIBCPP_INLINE_VISIBILITY
449 typename __invoke_return1<type, _A0 const, _A1 const>::type
450 operator() (_A0 const& __a0, _A1 const& __a1) const {
451 return __invoke(get(), __a0, __a1);
452 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000453
454 template <class _A0, class _A1, class _A2>
Eric Fiselier70192a92015-08-26 20:15:02 +0000455 _LIBCPP_INLINE_VISIBILITY
456 typename __invoke_return2<type, _A0, _A1, _A2>::type
457 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
458 return __invoke(get(), __a0, __a1, __a2);
459 }
460
461 template <class _A0, class _A1, class _A2>
462 _LIBCPP_INLINE_VISIBILITY
463 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
464 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
465 return __invoke(get(), __a0, __a1, __a2);
466 }
467
468 template <class _A0, class _A1, class _A2>
469 _LIBCPP_INLINE_VISIBILITY
470 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
471 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
472 return __invoke(get(), __a0, __a1, __a2);
473 }
474
475 template <class _A0, class _A1, class _A2>
476 _LIBCPP_INLINE_VISIBILITY
477 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
478 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
479 return __invoke(get(), __a0, __a1, __a2);
480 }
481
482 template <class _A0, class _A1, class _A2>
483 _LIBCPP_INLINE_VISIBILITY
484 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
485 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
486 return __invoke(get(), __a0, __a1, __a2);
487 }
488
489 template <class _A0, class _A1, class _A2>
490 _LIBCPP_INLINE_VISIBILITY
491 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
492 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
493 return __invoke(get(), __a0, __a1, __a2);
494 }
495
496 template <class _A0, class _A1, class _A2>
497 _LIBCPP_INLINE_VISIBILITY
498 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
499 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
500 return __invoke(get(), __a0, __a1, __a2);
501 }
502
503 template <class _A0, class _A1, class _A2>
504 _LIBCPP_INLINE_VISIBILITY
505 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
506 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
507 return __invoke(get(), __a0, __a1, __a2);
508 }
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000509#endif // _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000510};
511
Howard Hinnant3e519522010-05-11 19:42:16 +0000512
513template <class _Tp>
514inline _LIBCPP_INLINE_VISIBILITY
515reference_wrapper<_Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000516ref(_Tp& __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000517{
518 return reference_wrapper<_Tp>(__t);
519}
520
521template <class _Tp>
522inline _LIBCPP_INLINE_VISIBILITY
523reference_wrapper<_Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000524ref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000525{
526 return ref(__t.get());
527}
528
529template <class _Tp>
530inline _LIBCPP_INLINE_VISIBILITY
531reference_wrapper<const _Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000532cref(const _Tp& __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000533{
534 return reference_wrapper<const _Tp>(__t);
535}
536
537template <class _Tp>
538inline _LIBCPP_INLINE_VISIBILITY
539reference_wrapper<const _Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000540cref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000541{
542 return cref(__t.get());
543}
544
Eric Fiselier8f56ded2017-01-06 20:58:25 +0000545#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc2063662011-12-01 20:21:04 +0000546template <class _Tp> void ref(const _Tp&&) = delete;
547template <class _Tp> void cref(const _Tp&&) = delete;
Eric Fiselier8f56ded2017-01-06 20:58:25 +0000548#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000549
Marshall Clow25d34022013-08-13 01:11:06 +0000550#if _LIBCPP_STD_VER > 11
Marshall Clowb707e7f2017-06-13 14:34:58 +0000551template <class _Tp, class, class = void>
552struct __is_transparent : false_type {};
553
554template <class _Tp, class _Up>
555struct __is_transparent<_Tp, _Up,
556 typename __void_t<typename _Tp::is_transparent>::type>
557 : true_type {};
Marshall Clow25d34022013-08-13 01:11:06 +0000558#endif
559
Marshall Clow50c003b2013-09-12 02:11:16 +0000560// allocator_arg_t
561
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000562struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { };
Marshall Clow50c003b2013-09-12 02:11:16 +0000563
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000564#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_MEMORY)
Marshall Clow50c003b2013-09-12 02:11:16 +0000565extern const allocator_arg_t allocator_arg;
566#else
567constexpr allocator_arg_t allocator_arg = allocator_arg_t();
568#endif
569
570// uses_allocator
571
572template <class _Tp>
573struct __has_allocator_type
574{
575private:
576 struct __two {char __lx; char __lxx;};
577 template <class _Up> static __two __test(...);
578 template <class _Up> static char __test(typename _Up::allocator_type* = 0);
579public:
580 static const bool value = sizeof(__test<_Tp>(0)) == 1;
581};
582
583template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
584struct __uses_allocator
585 : public integral_constant<bool,
586 is_convertible<_Alloc, typename _Tp::allocator_type>::value>
587{
588};
589
590template <class _Tp, class _Alloc>
591struct __uses_allocator<_Tp, _Alloc, false>
592 : public false_type
593{
594};
595
596template <class _Tp, class _Alloc>
Eric Fiseliere2f2d1e2017-01-04 23:56:00 +0000597struct _LIBCPP_TEMPLATE_VIS uses_allocator
Marshall Clow50c003b2013-09-12 02:11:16 +0000598 : public __uses_allocator<_Tp, _Alloc>
599{
600};
601
Marshall Clowa48055c2016-09-22 00:23:15 +0000602#if _LIBCPP_STD_VER > 14
603template <class _Tp, class _Alloc>
604constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
605#endif
606
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000607#ifndef _LIBCPP_CXX03_LANG
Marshall Clow50c003b2013-09-12 02:11:16 +0000608
609// allocator construction
610
611template <class _Tp, class _Alloc, class ..._Args>
612struct __uses_alloc_ctor_imp
613{
Eric Fiselier4ffd08c2016-12-14 21:29:29 +0000614 typedef typename __uncvref<_Alloc>::type _RawAlloc;
615 static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;
Marshall Clow50c003b2013-09-12 02:11:16 +0000616 static const bool __ic =
617 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
618 static const int value = __ua ? 2 - __ic : 0;
619};
620
621template <class _Tp, class _Alloc, class ..._Args>
622struct __uses_alloc_ctor
623 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
624 {};
625
626template <class _Tp, class _Allocator, class... _Args>
627inline _LIBCPP_INLINE_VISIBILITY
628void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
629{
630 new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
631}
632
Eric Fiselier4ffd08c2016-12-14 21:29:29 +0000633// FIXME: This should have a version which takes a non-const alloc.
Marshall Clow50c003b2013-09-12 02:11:16 +0000634template <class _Tp, class _Allocator, class... _Args>
635inline _LIBCPP_INLINE_VISIBILITY
636void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
637{
638 new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
639}
640
Eric Fiselier4ffd08c2016-12-14 21:29:29 +0000641// FIXME: This should have a version which takes a non-const alloc.
Marshall Clow50c003b2013-09-12 02:11:16 +0000642template <class _Tp, class _Allocator, class... _Args>
643inline _LIBCPP_INLINE_VISIBILITY
644void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
645{
646 new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
647}
648
Eric Fiselier4ffd08c2016-12-14 21:29:29 +0000649// FIXME: Theis should have a version which takes a non-const alloc.
Marshall Clow50c003b2013-09-12 02:11:16 +0000650template <class _Tp, class _Allocator, class... _Args>
651inline _LIBCPP_INLINE_VISIBILITY
652void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args)
653{
654 __user_alloc_construct_impl(
655 __uses_alloc_ctor<_Tp, _Allocator>(),
656 __storage, __a, _VSTD::forward<_Args>(__args)...
657 );
658}
Eric Fiselier7e23afc2017-04-19 01:28:47 +0000659#endif // _LIBCPP_CXX03_LANG
Marshall Clow25d34022013-08-13 01:11:06 +0000660
Howard Hinnant3e519522010-05-11 19:42:16 +0000661_LIBCPP_END_NAMESPACE_STD
662
663#endif // _LIBCPP_FUNCTIONAL_BASE