blob: feb587f7b55a9d7658c810b575b3dbffc8dd80f4 [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 Hinnantf0544c22013-08-12 18:38:34 +000041template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
Howard Hinnant3e519522010-05-11 19:42:16 +000042
43template <class _Tp>
44struct __has_result_type
45{
46private:
Howard Hinnant54d333a2012-10-30 19:06:59 +000047 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +000048 template <class _Up> static __two __test(...);
49 template <class _Up> static char __test(typename _Up::result_type* = 0);
50public:
51 static const bool value = sizeof(__test<_Tp>(0)) == 1;
52};
53
Marshall Clow83c08b42013-07-29 14:21:53 +000054#if _LIBCPP_STD_VER > 11
55template <class _Tp = void>
56#else
Howard Hinnant67f39642012-02-21 21:02:58 +000057template <class _Tp>
Marshall Clow83c08b42013-07-29 14:21:53 +000058#endif
Howard Hinnantf0544c22013-08-12 18:38:34 +000059struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool>
Howard Hinnant67f39642012-02-21 21:02:58 +000060{
Marshall Clow3d5134dd2013-09-28 19:06:12 +000061 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
62 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnant67f39642012-02-21 21:02:58 +000063 {return __x < __y;}
64};
65
Marshall Clow83c08b42013-07-29 14:21:53 +000066#if _LIBCPP_STD_VER > 11
67template <>
Howard Hinnantf0544c22013-08-12 18:38:34 +000068struct _LIBCPP_TYPE_VIS_ONLY less<void>
Marshall Clow83c08b42013-07-29 14:21:53 +000069{
Marshall Clow3d5134dd2013-09-28 19:06:12 +000070 template <class _T1, class _T2>
71 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow83c08b42013-07-29 14:21:53 +000072 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowa64f2fb2015-02-25 12:20:52 +000073 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
74 -> decltype (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
75 { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
Marshall Clow25d34022013-08-13 01:11:06 +000076 typedef void is_transparent;
Marshall Clow83c08b42013-07-29 14:21:53 +000077};
78#endif
79
Howard Hinnant3e519522010-05-11 19:42:16 +000080// __weak_result_type
81
82template <class _Tp>
83struct __derives_from_unary_function
84{
85private:
Howard Hinnant54d333a2012-10-30 19:06:59 +000086 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +000087 static __two __test(...);
Howard Hinnantc003db12011-11-29 18:15:50 +000088 template <class _Ap, class _Rp>
89 static unary_function<_Ap, _Rp>
90 __test(const volatile unary_function<_Ap, _Rp>*);
Howard Hinnant3e519522010-05-11 19:42:16 +000091public:
92 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
93 typedef decltype(__test((_Tp*)0)) type;
94};
95
96template <class _Tp>
97struct __derives_from_binary_function
98{
99private:
Howard Hinnant54d333a2012-10-30 19:06:59 +0000100 struct __two {char __lx; char __lxx;};
Howard Hinnant3e519522010-05-11 19:42:16 +0000101 static __two __test(...);
Howard Hinnantc003db12011-11-29 18:15:50 +0000102 template <class _A1, class _A2, class _Rp>
103 static binary_function<_A1, _A2, _Rp>
104 __test(const volatile binary_function<_A1, _A2, _Rp>*);
Howard Hinnant3e519522010-05-11 19:42:16 +0000105public:
106 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
107 typedef decltype(__test((_Tp*)0)) type;
108};
109
110template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
111struct __maybe_derive_from_unary_function // bool is true
112 : public __derives_from_unary_function<_Tp>::type
113{
114};
115
116template <class _Tp>
117struct __maybe_derive_from_unary_function<_Tp, false>
118{
119};
120
121template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
122struct __maybe_derive_from_binary_function // bool is true
123 : public __derives_from_binary_function<_Tp>::type
124{
125};
126
127template <class _Tp>
128struct __maybe_derive_from_binary_function<_Tp, false>
129{
130};
131
132template <class _Tp, bool = __has_result_type<_Tp>::value>
133struct __weak_result_type_imp // bool is true
134 : public __maybe_derive_from_unary_function<_Tp>,
135 public __maybe_derive_from_binary_function<_Tp>
136{
137 typedef typename _Tp::result_type result_type;
138};
139
140template <class _Tp>
141struct __weak_result_type_imp<_Tp, false>
142 : public __maybe_derive_from_unary_function<_Tp>,
143 public __maybe_derive_from_binary_function<_Tp>
144{
145};
146
147template <class _Tp>
148struct __weak_result_type
149 : public __weak_result_type_imp<_Tp>
150{
151};
152
153// 0 argument case
154
Howard Hinnantc003db12011-11-29 18:15:50 +0000155template <class _Rp>
156struct __weak_result_type<_Rp ()>
Howard Hinnant3e519522010-05-11 19:42:16 +0000157{
Howard Hinnantc003db12011-11-29 18:15:50 +0000158 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000159};
160
Howard Hinnantc003db12011-11-29 18:15:50 +0000161template <class _Rp>
162struct __weak_result_type<_Rp (&)()>
Howard Hinnant3e519522010-05-11 19:42:16 +0000163{
Howard Hinnantc003db12011-11-29 18:15:50 +0000164 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000165};
166
Howard Hinnantc003db12011-11-29 18:15:50 +0000167template <class _Rp>
168struct __weak_result_type<_Rp (*)()>
Howard Hinnant3e519522010-05-11 19:42:16 +0000169{
Howard Hinnantc003db12011-11-29 18:15:50 +0000170 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000171};
172
173// 1 argument case
174
Howard Hinnantc003db12011-11-29 18:15:50 +0000175template <class _Rp, class _A1>
176struct __weak_result_type<_Rp (_A1)>
177 : public unary_function<_A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000178{
179};
180
Howard Hinnantc003db12011-11-29 18:15:50 +0000181template <class _Rp, class _A1>
182struct __weak_result_type<_Rp (&)(_A1)>
183 : public unary_function<_A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000184{
185};
186
Howard Hinnantc003db12011-11-29 18:15:50 +0000187template <class _Rp, class _A1>
188struct __weak_result_type<_Rp (*)(_A1)>
189 : public unary_function<_A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000190{
191};
192
Howard Hinnantc003db12011-11-29 18:15:50 +0000193template <class _Rp, class _Cp>
194struct __weak_result_type<_Rp (_Cp::*)()>
195 : public unary_function<_Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000196{
197};
198
Howard Hinnantc003db12011-11-29 18:15:50 +0000199template <class _Rp, class _Cp>
200struct __weak_result_type<_Rp (_Cp::*)() const>
201 : public unary_function<const _Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000202{
203};
204
Howard Hinnantc003db12011-11-29 18:15:50 +0000205template <class _Rp, class _Cp>
206struct __weak_result_type<_Rp (_Cp::*)() volatile>
207 : public unary_function<volatile _Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000208{
209};
210
Howard Hinnantc003db12011-11-29 18:15:50 +0000211template <class _Rp, class _Cp>
212struct __weak_result_type<_Rp (_Cp::*)() const volatile>
213 : public unary_function<const volatile _Cp*, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000214{
215};
216
217// 2 argument case
218
Howard Hinnantc003db12011-11-29 18:15:50 +0000219template <class _Rp, class _A1, class _A2>
220struct __weak_result_type<_Rp (_A1, _A2)>
221 : public binary_function<_A1, _A2, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000222{
223};
224
Howard Hinnantc003db12011-11-29 18:15:50 +0000225template <class _Rp, class _A1, class _A2>
226struct __weak_result_type<_Rp (*)(_A1, _A2)>
227 : public binary_function<_A1, _A2, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000228{
229};
230
Howard Hinnantc003db12011-11-29 18:15:50 +0000231template <class _Rp, class _A1, class _A2>
232struct __weak_result_type<_Rp (&)(_A1, _A2)>
233 : public binary_function<_A1, _A2, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000234{
235};
236
Howard Hinnantc003db12011-11-29 18:15:50 +0000237template <class _Rp, class _Cp, class _A1>
238struct __weak_result_type<_Rp (_Cp::*)(_A1)>
239 : public binary_function<_Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000240{
241};
242
Howard Hinnantc003db12011-11-29 18:15:50 +0000243template <class _Rp, class _Cp, class _A1>
244struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
245 : public binary_function<const _Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000246{
247};
248
Howard Hinnantc003db12011-11-29 18:15:50 +0000249template <class _Rp, class _Cp, class _A1>
250struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
251 : public binary_function<volatile _Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000252{
253};
254
Howard Hinnantc003db12011-11-29 18:15:50 +0000255template <class _Rp, class _Cp, class _A1>
256struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
257 : public binary_function<const volatile _Cp*, _A1, _Rp>
Howard Hinnant3e519522010-05-11 19:42:16 +0000258{
259};
260
Eric Fiselier48cf1282015-07-22 22:23:49 +0000261
262#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000263// 3 or more arguments
264
Howard Hinnantc003db12011-11-29 18:15:50 +0000265template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
266struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
Howard Hinnant3e519522010-05-11 19:42:16 +0000267{
Howard Hinnantc003db12011-11-29 18:15:50 +0000268 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000269};
270
Howard Hinnantc003db12011-11-29 18:15:50 +0000271template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
272struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
Howard Hinnant3e519522010-05-11 19:42:16 +0000273{
Howard Hinnantc003db12011-11-29 18:15:50 +0000274 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000275};
276
Howard Hinnantc003db12011-11-29 18:15:50 +0000277template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
278struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
Howard Hinnant3e519522010-05-11 19:42:16 +0000279{
Howard Hinnantc003db12011-11-29 18:15:50 +0000280 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000281};
282
Howard Hinnantc003db12011-11-29 18:15:50 +0000283template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
284struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
Howard Hinnant3e519522010-05-11 19:42:16 +0000285{
Howard Hinnantc003db12011-11-29 18:15:50 +0000286 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000287};
288
Howard Hinnantc003db12011-11-29 18:15:50 +0000289template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
290struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
Howard Hinnant3e519522010-05-11 19:42:16 +0000291{
Howard Hinnantc003db12011-11-29 18:15:50 +0000292 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000293};
294
Howard Hinnantc003db12011-11-29 18:15:50 +0000295template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
296struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
Howard Hinnant3e519522010-05-11 19:42:16 +0000297{
Howard Hinnantc003db12011-11-29 18:15:50 +0000298 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000299};
300
Howard Hinnantc003db12011-11-29 18:15:50 +0000301template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
302struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
Howard Hinnant3e519522010-05-11 19:42:16 +0000303{
Howard Hinnantc003db12011-11-29 18:15:50 +0000304 typedef _Rp result_type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000305};
306
Eric Fiselier48cf1282015-07-22 22:23:49 +0000307#endif // _LIBCPP_HAS_NO_VARIADICS
308
Eric Fiselier840fa742016-04-20 00:14:32 +0000309#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant3e519522010-05-11 19:42:16 +0000310
Howard Hinnant3e519522010-05-11 19:42:16 +0000311template <class _Tp, class ..._Args>
312struct __invoke_return
313{
Howard Hinnantce48a112011-06-30 21:18:19 +0000314 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
Howard Hinnant3e519522010-05-11 19:42:16 +0000315};
316
Eric Fiselier840fa742016-04-20 00:14:32 +0000317#else // defined(_LIBCPP_CXX03_LANG)
Eric Fiselier48cf1282015-07-22 22:23:49 +0000318
319#include <__functional_base_03>
320
Eric Fiselier840fa742016-04-20 00:14:32 +0000321#endif // !defined(_LIBCPP_CXX03_LANG)
Eric Fiselier48cf1282015-07-22 22:23:49 +0000322
323
Eric Fiselier54519a62015-02-10 16:48:45 +0000324template <class _Ret>
325struct __invoke_void_return_wrapper
326{
Eric Fiselier48cf1282015-07-22 22:23:49 +0000327#ifndef _LIBCPP_HAS_NO_VARIADICS
Eric Fiselier54519a62015-02-10 16:48:45 +0000328 template <class ..._Args>
Eric Fiselier48cf1282015-07-22 22:23:49 +0000329 static _Ret __call(_Args&&... __args) {
Eric Fiselier54519a62015-02-10 16:48:45 +0000330 return __invoke(_VSTD::forward<_Args>(__args)...);
331 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000332#else
333 template <class _Fn>
334 static _Ret __call(_Fn __f) {
335 return __invoke(__f);
336 }
337
338 template <class _Fn, class _A0>
339 static _Ret __call(_Fn __f, _A0& __a0) {
340 return __invoke(__f, __a0);
341 }
342
343 template <class _Fn, class _A0, class _A1>
344 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
345 return __invoke(__f, __a0, __a1);
346 }
347
348 template <class _Fn, class _A0, class _A1, class _A2>
349 static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
350 return __invoke(__f, __a0, __a1, __a2);
351 }
352#endif
Eric Fiselier54519a62015-02-10 16:48:45 +0000353};
354
355template <>
356struct __invoke_void_return_wrapper<void>
357{
Eric Fiselier48cf1282015-07-22 22:23:49 +0000358#ifndef _LIBCPP_HAS_NO_VARIADICS
Eric Fiselier54519a62015-02-10 16:48:45 +0000359 template <class ..._Args>
Eric Fiselier48cf1282015-07-22 22:23:49 +0000360 static void __call(_Args&&... __args) {
Eric Fiselier54519a62015-02-10 16:48:45 +0000361 __invoke(_VSTD::forward<_Args>(__args)...);
362 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000363#else
364 template <class _Fn>
365 static void __call(_Fn __f) {
366 __invoke(__f);
367 }
368
369 template <class _Fn, class _A0>
370 static void __call(_Fn __f, _A0& __a0) {
371 __invoke(__f, __a0);
372 }
373
374 template <class _Fn, class _A0, class _A1>
375 static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
376 __invoke(__f, __a0, __a1);
377 }
378
379 template <class _Fn, class _A0, class _A1, class _A2>
380 static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
381 __invoke(__f, __a0, __a1, __a2);
382 }
383#endif
Eric Fiselier54519a62015-02-10 16:48:45 +0000384};
385
Howard Hinnant3e519522010-05-11 19:42:16 +0000386template <class _Tp>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000387class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
Howard Hinnant3e519522010-05-11 19:42:16 +0000388 : public __weak_result_type<_Tp>
389{
390public:
391 // types
392 typedef _Tp type;
393private:
394 type* __f_;
395
396public:
397 // construct/copy/destroy
Howard Hinnant8c974202013-08-08 18:38:55 +0000398 _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
399 : __f_(_VSTD::addressof(__f)) {}
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000400#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000401 private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
402#endif
403
404 // access
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000405 _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;}
406 _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000407
Eric Fiselier48cf1282015-07-22 22:23:49 +0000408#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000409 // invoke
410 template <class... _ArgTypes>
Eric Fiselier70192a92015-08-26 20:15:02 +0000411 _LIBCPP_INLINE_VISIBILITY
412 typename __invoke_of<type&, _ArgTypes...>::type
413 operator() (_ArgTypes&&... __args) const {
414 return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
415 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000416#else
417
418 _LIBCPP_INLINE_VISIBILITY
419 typename __invoke_return<type>::type
Eric Fiselier70192a92015-08-26 20:15:02 +0000420 operator() () const {
421 return __invoke(get());
422 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000423
424 template <class _A0>
Eric Fiselier70192a92015-08-26 20:15:02 +0000425 _LIBCPP_INLINE_VISIBILITY
426 typename __invoke_return0<type, _A0>::type
427 operator() (_A0& __a0) const {
428 return __invoke(get(), __a0);
429 }
430
431 template <class _A0>
432 _LIBCPP_INLINE_VISIBILITY
433 typename __invoke_return0<type, _A0 const>::type
434 operator() (_A0 const& __a0) const {
435 return __invoke(get(), __a0);
436 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000437
438 template <class _A0, class _A1>
Eric Fiselier70192a92015-08-26 20:15:02 +0000439 _LIBCPP_INLINE_VISIBILITY
440 typename __invoke_return1<type, _A0, _A1>::type
441 operator() (_A0& __a0, _A1& __a1) const {
442 return __invoke(get(), __a0, __a1);
443 }
444
445 template <class _A0, class _A1>
446 _LIBCPP_INLINE_VISIBILITY
447 typename __invoke_return1<type, _A0 const, _A1>::type
448 operator() (_A0 const& __a0, _A1& __a1) const {
449 return __invoke(get(), __a0, __a1);
450 }
451
452 template <class _A0, class _A1>
453 _LIBCPP_INLINE_VISIBILITY
454 typename __invoke_return1<type, _A0, _A1 const>::type
455 operator() (_A0& __a0, _A1 const& __a1) const {
456 return __invoke(get(), __a0, __a1);
457 }
458
459 template <class _A0, class _A1>
460 _LIBCPP_INLINE_VISIBILITY
461 typename __invoke_return1<type, _A0 const, _A1 const>::type
462 operator() (_A0 const& __a0, _A1 const& __a1) const {
463 return __invoke(get(), __a0, __a1);
464 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000465
466 template <class _A0, class _A1, class _A2>
Eric Fiselier70192a92015-08-26 20:15:02 +0000467 _LIBCPP_INLINE_VISIBILITY
468 typename __invoke_return2<type, _A0, _A1, _A2>::type
469 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
470 return __invoke(get(), __a0, __a1, __a2);
471 }
472
473 template <class _A0, class _A1, class _A2>
474 _LIBCPP_INLINE_VISIBILITY
475 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
476 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
477 return __invoke(get(), __a0, __a1, __a2);
478 }
479
480 template <class _A0, class _A1, class _A2>
481 _LIBCPP_INLINE_VISIBILITY
482 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
483 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
484 return __invoke(get(), __a0, __a1, __a2);
485 }
486
487 template <class _A0, class _A1, class _A2>
488 _LIBCPP_INLINE_VISIBILITY
489 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
490 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
491 return __invoke(get(), __a0, __a1, __a2);
492 }
493
494 template <class _A0, class _A1, class _A2>
495 _LIBCPP_INLINE_VISIBILITY
496 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
497 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
498 return __invoke(get(), __a0, __a1, __a2);
499 }
500
501 template <class _A0, class _A1, class _A2>
502 _LIBCPP_INLINE_VISIBILITY
503 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
504 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
505 return __invoke(get(), __a0, __a1, __a2);
506 }
507
508 template <class _A0, class _A1, class _A2>
509 _LIBCPP_INLINE_VISIBILITY
510 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
511 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
512 return __invoke(get(), __a0, __a1, __a2);
513 }
514
515 template <class _A0, class _A1, class _A2>
516 _LIBCPP_INLINE_VISIBILITY
517 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
518 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
519 return __invoke(get(), __a0, __a1, __a2);
520 }
Eric Fiselier48cf1282015-07-22 22:23:49 +0000521#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000522};
523
Howard Hinnant3e519522010-05-11 19:42:16 +0000524
525template <class _Tp>
526inline _LIBCPP_INLINE_VISIBILITY
527reference_wrapper<_Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000528ref(_Tp& __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000529{
530 return reference_wrapper<_Tp>(__t);
531}
532
533template <class _Tp>
534inline _LIBCPP_INLINE_VISIBILITY
535reference_wrapper<_Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000536ref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000537{
538 return ref(__t.get());
539}
540
541template <class _Tp>
542inline _LIBCPP_INLINE_VISIBILITY
543reference_wrapper<const _Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000544cref(const _Tp& __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000545{
546 return reference_wrapper<const _Tp>(__t);
547}
548
549template <class _Tp>
550inline _LIBCPP_INLINE_VISIBILITY
551reference_wrapper<const _Tp>
Howard Hinnant6a07d6f2011-05-28 17:59:48 +0000552cref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000553{
554 return cref(__t.get());
555}
556
Eric Fiselier48cf1282015-07-22 22:23:49 +0000557#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000558#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
559#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
560
Howard Hinnantc2063662011-12-01 20:21:04 +0000561template <class _Tp> void ref(const _Tp&&) = delete;
562template <class _Tp> void cref(const _Tp&&) = delete;
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000563
564#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
565
Howard Hinnantc2063662011-12-01 20:21:04 +0000566template <class _Tp> void ref(const _Tp&&);// = delete;
567template <class _Tp> void cref(const _Tp&&);// = delete;
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000568
569#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
570
571#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000572
573#endif // _LIBCPP_HAS_NO_VARIADICS
574
Marshall Clow25d34022013-08-13 01:11:06 +0000575#if _LIBCPP_STD_VER > 11
576template <class _Tp1, class _Tp2 = void>
577struct __is_transparent
578{
579private:
580 struct __two {char __lx; char __lxx;};
581 template <class _Up> static __two __test(...);
582 template <class _Up> static char __test(typename _Up::is_transparent* = 0);
583public:
584 static const bool value = sizeof(__test<_Tp1>(0)) == 1;
585};
586#endif
587
Marshall Clow50c003b2013-09-12 02:11:16 +0000588// allocator_arg_t
589
590struct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { };
591
592#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY)
593extern const allocator_arg_t allocator_arg;
594#else
595constexpr allocator_arg_t allocator_arg = allocator_arg_t();
596#endif
597
598// uses_allocator
599
600template <class _Tp>
601struct __has_allocator_type
602{
603private:
604 struct __two {char __lx; char __lxx;};
605 template <class _Up> static __two __test(...);
606 template <class _Up> static char __test(typename _Up::allocator_type* = 0);
607public:
608 static const bool value = sizeof(__test<_Tp>(0)) == 1;
609};
610
611template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
612struct __uses_allocator
613 : public integral_constant<bool,
614 is_convertible<_Alloc, typename _Tp::allocator_type>::value>
615{
616};
617
618template <class _Tp, class _Alloc>
619struct __uses_allocator<_Tp, _Alloc, false>
620 : public false_type
621{
622};
623
624template <class _Tp, class _Alloc>
625struct _LIBCPP_TYPE_VIS_ONLY uses_allocator
626 : public __uses_allocator<_Tp, _Alloc>
627{
628};
629
630#ifndef _LIBCPP_HAS_NO_VARIADICS
631
632// allocator construction
633
634template <class _Tp, class _Alloc, class ..._Args>
635struct __uses_alloc_ctor_imp
636{
637 static const bool __ua = uses_allocator<_Tp, _Alloc>::value;
638 static const bool __ic =
639 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
640 static const int value = __ua ? 2 - __ic : 0;
641};
642
643template <class _Tp, class _Alloc, class ..._Args>
644struct __uses_alloc_ctor
645 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
646 {};
647
648template <class _Tp, class _Allocator, class... _Args>
649inline _LIBCPP_INLINE_VISIBILITY
650void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
651{
652 new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
653}
654
655template <class _Tp, class _Allocator, class... _Args>
656inline _LIBCPP_INLINE_VISIBILITY
657void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
658{
659 new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
660}
661
662template <class _Tp, class _Allocator, class... _Args>
663inline _LIBCPP_INLINE_VISIBILITY
664void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
665{
666 new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
667}
668
669template <class _Tp, class _Allocator, class... _Args>
670inline _LIBCPP_INLINE_VISIBILITY
671void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args)
672{
673 __user_alloc_construct_impl(
674 __uses_alloc_ctor<_Tp, _Allocator>(),
675 __storage, __a, _VSTD::forward<_Args>(__args)...
676 );
677}
678#endif // _LIBCPP_HAS_NO_VARIADICS
Marshall Clow25d34022013-08-13 01:11:06 +0000679
Howard Hinnant3e519522010-05-11 19:42:16 +0000680_LIBCPP_END_NAMESPACE_STD
681
682#endif // _LIBCPP_FUNCTIONAL_BASE