blob: 82b414674ea783e8abf4e042f664796417fb1ccb [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>
Howard Hinnant3e519522010-05-11 19:42:16 +000019
Howard Hinnant073458b2011-10-17 20:05:10 +000020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +000021#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +000022#endif
Howard Hinnant3e519522010-05-11 19:42:16 +000023
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26template <class _Arg, class _Result>
Howard Hinnantf0544c22013-08-12 18:38:34 +000027struct _LIBCPP_TYPE_VIS_ONLY unary_function
Howard Hinnant3e519522010-05-11 19:42:16 +000028{
29 typedef _Arg argument_type;
30 typedef _Result result_type;
31};
32
33template <class _Arg1, class _Arg2, class _Result>
Howard Hinnantf0544c22013-08-12 18:38:34 +000034struct _LIBCPP_TYPE_VIS_ONLY binary_function
Howard Hinnant3e519522010-05-11 19:42:16 +000035{
36 typedef _Arg1 first_argument_type;
37 typedef _Arg2 second_argument_type;
38 typedef _Result result_type;
39};
40
Howard Hinnant3e519522010-05-11 19:42:16 +000041template <class _Tp>
42struct __has_result_type
43{
44private:
Howard Hinnant54d333a2012-10-30 19:06:59 +000045 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +000046 template <class _Up> static __two __test(...);
47 template <class _Up> static char __test(typename _Up::result_type* = 0);
48public:
49 static const bool value = sizeof(__test<_Tp>(0)) == 1;
50};
51
Marshall Clow83c08b42013-07-29 14:21:53 +000052#if _LIBCPP_STD_VER > 11
53template <class _Tp = void>
54#else
Howard Hinnant67f39642012-02-21 21:02:58 +000055template <class _Tp>
Marshall Clow83c08b42013-07-29 14:21:53 +000056#endif
Howard Hinnantf0544c22013-08-12 18:38:34 +000057struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool>
Howard Hinnant67f39642012-02-21 21:02:58 +000058{
Marshall Clow3d5134dd2013-09-28 19:06:12 +000059 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
60 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnant67f39642012-02-21 21:02:58 +000061 {return __x < __y;}
62};
63
Marshall Clow83c08b42013-07-29 14:21:53 +000064#if _LIBCPP_STD_VER > 11
65template <>
Howard Hinnantf0544c22013-08-12 18:38:34 +000066struct _LIBCPP_TYPE_VIS_ONLY less<void>
Marshall Clow83c08b42013-07-29 14:21:53 +000067{
Marshall Clow3d5134dd2013-09-28 19:06:12 +000068 template <class _T1, class _T2>
69 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow83c08b42013-07-29 14:21:53 +000070 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowa64f2fb2015-02-25 12:20:52 +000071 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
72 -> decltype (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
73 { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
Marshall Clow25d34022013-08-13 01:11:06 +000074 typedef void is_transparent;
Marshall Clow83c08b42013-07-29 14:21:53 +000075};
76#endif
77
Howard Hinnant3e519522010-05-11 19:42:16 +000078// __weak_result_type
79
80template <class _Tp>
81struct __derives_from_unary_function
82{
83private:
Howard Hinnant54d333a2012-10-30 19:06:59 +000084 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +000085 static __two __test(...);
Howard Hinnantc003db12011-11-29 18:15:50 +000086 template <class _Ap, class _Rp>
87 static unary_function<_Ap, _Rp>
88 __test(const volatile unary_function<_Ap, _Rp>*);
Howard Hinnant3e519522010-05-11 19:42:16 +000089public:
90 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
91 typedef decltype(__test((_Tp*)0)) type;
92};
93
94template <class _Tp>
95struct __derives_from_binary_function
96{
97private:
Howard Hinnant54d333a2012-10-30 19:06:59 +000098 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +000099 static __two __test(...);
Howard Hinnantc003db12011-11-29 18:15:50 +0000100 template <class _A1, class _A2, class _Rp>
101 static binary_function<_A1, _A2, _Rp>
102 __test(const volatile binary_function<_A1, _A2, _Rp>*);
Howard Hinnant3e519522010-05-11 19:42:16 +0000103public:
104 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
105 typedef decltype(__test((_Tp*)0)) type;
106};
107
108template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
109struct __maybe_derive_from_unary_function // bool is true
110 : public __derives_from_unary_function<_Tp>::type
111{
112};
113
114template <class _Tp>
115struct __maybe_derive_from_unary_function<_Tp, false>
116{
117};
118
119template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
120struct __maybe_derive_from_binary_function // bool is true
121 : public __derives_from_binary_function<_Tp>::type
122{
123};
124
125template <class _Tp>
126struct __maybe_derive_from_binary_function<_Tp, false>
127{
128};
129
130template <class _Tp, bool = __has_result_type<_Tp>::value>
131struct __weak_result_type_imp // bool is true
132 : public __maybe_derive_from_unary_function<_Tp>,
133 public __maybe_derive_from_binary_function<_Tp>
134{
135 typedef typename _Tp::result_type result_type;
136};
137
138template <class _Tp>
139struct __weak_result_type_imp<_Tp, false>
140 : public __maybe_derive_from_unary_function<_Tp>,
141 public __maybe_derive_from_binary_function<_Tp>
142{
143};
144
145template <class _Tp>
146struct __weak_result_type
147 : public __weak_result_type_imp<_Tp>
148{
149};
150
151// 0 argument case
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
Howard Hinnantc003db12011-11-29 18:15:50 +0000165template <class _Rp>
166struct __weak_result_type<_Rp (*)()>
Howard Hinnant3e519522010-05-11 19:42:16 +0000167{
Howard Hinnantc003db12011-11-29 18:15:50 +0000168 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000169};
170
171// 1 argument case
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 _A1>
186struct __weak_result_type<_Rp (*)(_A1)>
187 : public unary_function<_A1, _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::*)()>
193 : public unary_function<_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::*)() const>
199 : public unary_function<const _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::*)() volatile>
205 : public unary_function<volatile _Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000206{
207};
208
Howard Hinnantc003db12011-11-29 18:15:50 +0000209template <class _Rp, class _Cp>
210struct __weak_result_type<_Rp (_Cp::*)() const volatile>
211 : public unary_function<const volatile _Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000212{
213};
214
215// 2 argument case
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 _A1, class _A2>
230struct __weak_result_type<_Rp (&)(_A1, _A2)>
231 : public binary_function<_A1, _A2, _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)>
237 : public binary_function<_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) const>
243 : public binary_function<const _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) volatile>
249 : public binary_function<volatile _Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000250{
251};
252
Howard Hinnantc003db12011-11-29 18:15:50 +0000253template <class _Rp, class _Cp, class _A1>
254struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
255 : public binary_function<const volatile _Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000256{
257};
258
Eric Fiselier48cf1282015-07-22 22:23:49 +0000259
260#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000261// 3 or more arguments
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 _A1, class _A2, class _A3, class ..._A4>
276struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
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...)>
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...) const>
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...) 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 Hinnantc003db12011-11-29 18:15:50 +0000299template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
300struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
Howard Hinnant3e519522010-05-11 19:42:16 +0000301{
Howard Hinnantc003db12011-11-29 18:15:50 +0000302 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000303};
304
Eric Fiselier48cf1282015-07-22 22:23:49 +0000305#endif // _LIBCPP_HAS_NO_VARIADICS
306
Eric Fiselier840fa742016-04-20 00:14:32 +0000307#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000308
Howard Hinnant3e519522010-05-11 19:42:16 +0000309template <class _Tp, class ..._Args>
310struct __invoke_return
311{
Howard Hinnantce48a112011-06-30 21:18:19 +0000312 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000313};
314
Eric Fiselier840fa742016-04-20 00:14:32 +0000315#else // defined(_LIBCPP_CXX03_LANG)
Eric Fiselier48cf1282015-07-22 22:23:49 +0000316
317#include <__functional_base_03>
318
Eric Fiselier840fa742016-04-20 00:14:32 +0000319#endif // !defined(_LIBCPP_CXX03_LANG)
Eric Fiselier48cf1282015-07-22 22:23:49 +0000320
321
Eric Fiselier54519a62015-02-10 16:48:45 +0000322template <class _Ret>
323struct __invoke_void_return_wrapper
324{
Eric Fiselier48cf1282015-07-22 22:23:49 +0000325#ifndef _LIBCPP_HAS_NO_VARIADICS
Eric Fiselier54519a62015-02-10 16:48:45 +0000326 template <class ..._Args>
Eric Fiselier48cf1282015-07-22 22:23:49 +0000327 static _Ret __call(_Args&&... __args) {
Eric Fiselier54519a62015-02-10 16:48:45 +0000328 return __invoke(_VSTD::forward<_Args>(__args)...);
329 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000330#else
331 template <class _Fn>
332 static _Ret __call(_Fn __f) {
333 return __invoke(__f);
334 }
335
336 template <class _Fn, class _A0>
337 static _Ret __call(_Fn __f, _A0& __a0) {
338 return __invoke(__f, __a0);
339 }
340
341 template <class _Fn, class _A0, class _A1>
342 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
343 return __invoke(__f, __a0, __a1);
344 }
345
346 template <class _Fn, class _A0, class _A1, class _A2>
347 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
348 return __invoke(__f, __a0, __a1, __a2);
349 }
350#endif
Eric Fiselier54519a62015-02-10 16:48:45 +0000351};
352
353template <>
354struct __invoke_void_return_wrapper<void>
355{
Eric Fiselier48cf1282015-07-22 22:23:49 +0000356#ifndef _LIBCPP_HAS_NO_VARIADICS
Eric Fiselier54519a62015-02-10 16:48:45 +0000357 template <class ..._Args>
Eric Fiselier48cf1282015-07-22 22:23:49 +0000358 static void __call(_Args&&... __args) {
Eric Fiselier54519a62015-02-10 16:48:45 +0000359 __invoke(_VSTD::forward<_Args>(__args)...);
360 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000361#else
362 template <class _Fn>
363 static void __call(_Fn __f) {
364 __invoke(__f);
365 }
366
367 template <class _Fn, class _A0>
368 static void __call(_Fn __f, _A0& __a0) {
369 __invoke(__f, __a0);
370 }
371
372 template <class _Fn, class _A0, class _A1>
373 static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
374 __invoke(__f, __a0, __a1);
375 }
376
377 template <class _Fn, class _A0, class _A1, class _A2>
378 static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
379 __invoke(__f, __a0, __a1, __a2);
380 }
381#endif
Eric Fiselier54519a62015-02-10 16:48:45 +0000382};
383
Howard Hinnant3e519522010-05-11 19:42:16 +0000384template <class _Tp>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000385class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
Howard Hinnant3e519522010-05-11 19:42:16 +0000386 : public __weak_result_type<_Tp>
387{
388public:
389 // types
390 typedef _Tp type;
391private:
392 type* __f_;
393
394public:
395 // construct/copy/destroy
Howard Hinnant8c974202013-08-08 18:38:55 +0000396 _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
397 : __f_(_VSTD::addressof(__f)) {}
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000398#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000399 private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
400#endif
401
402 // access
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000403 _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;}
404 _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000405
Eric Fiselier48cf1282015-07-22 22:23:49 +0000406#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000407 // invoke
408 template <class... _ArgTypes>
Eric Fiselier70192a92015-08-26 20:15:02 +0000409 _LIBCPP_INLINE_VISIBILITY
410 typename __invoke_of<type&, _ArgTypes...>::type
411 operator() (_ArgTypes&&... __args) const {
412 return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
413 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000414#else
415
416 _LIBCPP_INLINE_VISIBILITY
417 typename __invoke_return<type>::type
Eric Fiselier70192a92015-08-26 20:15:02 +0000418 operator() () const {
419 return __invoke(get());
420 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000421
422 template <class _A0>
Eric Fiselier70192a92015-08-26 20:15:02 +0000423 _LIBCPP_INLINE_VISIBILITY
424 typename __invoke_return0<type, _A0>::type
425 operator() (_A0& __a0) const {
426 return __invoke(get(), __a0);
427 }
428
429 template <class _A0>
430 _LIBCPP_INLINE_VISIBILITY
431 typename __invoke_return0<type, _A0 const>::type
432 operator() (_A0 const& __a0) const {
433 return __invoke(get(), __a0);
434 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000435
436 template <class _A0, class _A1>
Eric Fiselier70192a92015-08-26 20:15:02 +0000437 _LIBCPP_INLINE_VISIBILITY
438 typename __invoke_return1<type, _A0, _A1>::type
439 operator() (_A0& __a0, _A1& __a1) const {
440 return __invoke(get(), __a0, __a1);
441 }
442
443 template <class _A0, class _A1>
444 _LIBCPP_INLINE_VISIBILITY
445 typename __invoke_return1<type, _A0 const, _A1>::type
446 operator() (_A0 const& __a0, _A1& __a1) const {
447 return __invoke(get(), __a0, __a1);
448 }
449
450 template <class _A0, class _A1>
451 _LIBCPP_INLINE_VISIBILITY
452 typename __invoke_return1<type, _A0, _A1 const>::type
453 operator() (_A0& __a0, _A1 const& __a1) const {
454 return __invoke(get(), __a0, __a1);
455 }
456
457 template <class _A0, class _A1>
458 _LIBCPP_INLINE_VISIBILITY
459 typename __invoke_return1<type, _A0 const, _A1 const>::type
460 operator() (_A0 const& __a0, _A1 const& __a1) const {
461 return __invoke(get(), __a0, __a1);
462 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000463
464 template <class _A0, class _A1, class _A2>
Eric Fiselier70192a92015-08-26 20:15:02 +0000465 _LIBCPP_INLINE_VISIBILITY
466 typename __invoke_return2<type, _A0, _A1, _A2>::type
467 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
468 return __invoke(get(), __a0, __a1, __a2);
469 }
470
471 template <class _A0, class _A1, class _A2>
472 _LIBCPP_INLINE_VISIBILITY
473 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
474 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
475 return __invoke(get(), __a0, __a1, __a2);
476 }
477
478 template <class _A0, class _A1, class _A2>
479 _LIBCPP_INLINE_VISIBILITY
480 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
481 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
482 return __invoke(get(), __a0, __a1, __a2);
483 }
484
485 template <class _A0, class _A1, class _A2>
486 _LIBCPP_INLINE_VISIBILITY
487 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
488 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
489 return __invoke(get(), __a0, __a1, __a2);
490 }
491
492 template <class _A0, class _A1, class _A2>
493 _LIBCPP_INLINE_VISIBILITY
494 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
495 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
496 return __invoke(get(), __a0, __a1, __a2);
497 }
498
499 template <class _A0, class _A1, class _A2>
500 _LIBCPP_INLINE_VISIBILITY
501 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
502 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
503 return __invoke(get(), __a0, __a1, __a2);
504 }
505
506 template <class _A0, class _A1, class _A2>
507 _LIBCPP_INLINE_VISIBILITY
508 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
509 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
510 return __invoke(get(), __a0, __a1, __a2);
511 }
512
513 template <class _A0, class _A1, class _A2>
514 _LIBCPP_INLINE_VISIBILITY
515 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
516 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
517 return __invoke(get(), __a0, __a1, __a2);
518 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000519#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000520};
521
Howard Hinnant3e519522010-05-11 19:42:16 +0000522
523template <class _Tp>
524inline _LIBCPP_INLINE_VISIBILITY
525reference_wrapper<_Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000526ref(_Tp& __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000527{
528 return reference_wrapper<_Tp>(__t);
529}
530
531template <class _Tp>
532inline _LIBCPP_INLINE_VISIBILITY
533reference_wrapper<_Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000534ref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000535{
536 return ref(__t.get());
537}
538
539template <class _Tp>
540inline _LIBCPP_INLINE_VISIBILITY
541reference_wrapper<const _Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000542cref(const _Tp& __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000543{
544 return reference_wrapper<const _Tp>(__t);
545}
546
547template <class _Tp>
548inline _LIBCPP_INLINE_VISIBILITY
549reference_wrapper<const _Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000550cref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000551{
552 return cref(__t.get());
553}
554
Eric Fiselier48cf1282015-07-22 22:23:49 +0000555#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000556#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
557#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
558
Howard Hinnantc2063662011-12-01 20:21:04 +0000559template <class _Tp> void ref(const _Tp&&) = delete;
560template <class _Tp> void cref(const _Tp&&) = delete;
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000561
562#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
563
Howard Hinnantc2063662011-12-01 20:21:04 +0000564template <class _Tp> void ref(const _Tp&&);// = delete;
565template <class _Tp> void cref(const _Tp&&);// = delete;
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000566
567#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
568
569#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000570
571#endif // _LIBCPP_HAS_NO_VARIADICS
572
Marshall Clow25d34022013-08-13 01:11:06 +0000573#if _LIBCPP_STD_VER > 11
574template <class _Tp1, class _Tp2 = void>
575struct __is_transparent
576{
577private:
578 struct __two {char __lx; char __lxx;};
579 template <class _Up> static __two __test(...);
580 template <class _Up> static char __test(typename _Up::is_transparent* = 0);
581public:
582 static const bool value = sizeof(__test<_Tp1>(0)) == 1;
583};
584#endif
585
Marshall Clow50c003b2013-09-12 02:11:16 +0000586// allocator_arg_t
587
588struct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { };
589
590#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY)
591extern const allocator_arg_t allocator_arg;
592#else
593constexpr allocator_arg_t allocator_arg = allocator_arg_t();
594#endif
595
596// uses_allocator
597
598template <class _Tp>
599struct __has_allocator_type
600{
601private:
602 struct __two {char __lx; char __lxx;};
603 template <class _Up> static __two __test(...);
604 template <class _Up> static char __test(typename _Up::allocator_type* = 0);
605public:
606 static const bool value = sizeof(__test<_Tp>(0)) == 1;
607};
608
609template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
610struct __uses_allocator
611 : public integral_constant<bool,
612 is_convertible<_Alloc, typename _Tp::allocator_type>::value>
613{
614};
615
616template <class _Tp, class _Alloc>
617struct __uses_allocator<_Tp, _Alloc, false>
618 : public false_type
619{
620};
621
622template <class _Tp, class _Alloc>
623struct _LIBCPP_TYPE_VIS_ONLY uses_allocator
624 : public __uses_allocator<_Tp, _Alloc>
625{
626};
627
Marshall Clowa48055c2016-09-22 00:23:15 +0000628#if _LIBCPP_STD_VER > 14
629template <class _Tp, class _Alloc>
630constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
631#endif
632
Marshall Clow50c003b2013-09-12 02:11:16 +0000633#ifndef _LIBCPP_HAS_NO_VARIADICS
634
635// allocator construction
636
637template <class _Tp, class _Alloc, class ..._Args>
638struct __uses_alloc_ctor_imp
639{
640 static const bool __ua = uses_allocator<_Tp, _Alloc>::value;
641 static const bool __ic =
642 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
643 static const int value = __ua ? 2 - __ic : 0;
644};
645
646template <class _Tp, class _Alloc, class ..._Args>
647struct __uses_alloc_ctor
648 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
649 {};
650
651template <class _Tp, class _Allocator, class... _Args>
652inline _LIBCPP_INLINE_VISIBILITY
653void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
654{
655 new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
656}
657
658template <class _Tp, class _Allocator, class... _Args>
659inline _LIBCPP_INLINE_VISIBILITY
660void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
661{
662 new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
663}
664
665template <class _Tp, class _Allocator, class... _Args>
666inline _LIBCPP_INLINE_VISIBILITY
667void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
668{
669 new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
670}
671
672template <class _Tp, class _Allocator, class... _Args>
673inline _LIBCPP_INLINE_VISIBILITY
674void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args)
675{
676 __user_alloc_construct_impl(
677 __uses_alloc_ctor<_Tp, _Allocator>(),
678 __storage, __a, _VSTD::forward<_Args>(__args)...
679 );
680}
681#endif // _LIBCPP_HAS_NO_VARIADICS
Marshall Clow25d34022013-08-13 01:11:06 +0000682
Howard Hinnant3e519522010-05-11 19:42:16 +0000683_LIBCPP_END_NAMESPACE_STD
684
685#endif // _LIBCPP_FUNCTIONAL_BASE