1227825Stheraven// -*- C++ -*-
2227825Stheraven//===----------------------------------------------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open
7227825Stheraven// Source Licenses. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_FUNCTIONAL_BASE_03
12227825Stheraven#define _LIBCPP_FUNCTIONAL_BASE_03
13227825Stheraven
14227825Stheraven// manual variadic expansion for <functional>
15227825Stheraven
16227825Stheraven// __weak_result_type
17227825Stheraven
18227825Stheraventemplate <class _Tp>
19227825Stheravenstruct __derives_from_unary_function
20227825Stheraven{
21227825Stheravenprivate:
22242945Stheraven    struct __two {char __lx; char __lxx;};
23227825Stheraven    static __two __test(...);
24232950Stheraven    template <class _Ap, class _Rp>
25232950Stheraven        static unary_function<_Ap, _Rp>
26232950Stheraven        __test(const volatile unary_function<_Ap, _Rp>*);
27227825Stheravenpublic:
28227825Stheraven    static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
29227825Stheraven    typedef decltype(__test((_Tp*)0)) type;
30227825Stheraven};
31227825Stheraven
32227825Stheraventemplate <class _Tp>
33227825Stheravenstruct __derives_from_binary_function
34227825Stheraven{
35227825Stheravenprivate:
36242945Stheraven    struct __two {char __lx; char __lxx;};
37227825Stheraven    static __two __test(...);
38232950Stheraven    template <class _A1, class _A2, class _Rp>
39232950Stheraven        static binary_function<_A1, _A2, _Rp>
40232950Stheraven        __test(const volatile binary_function<_A1, _A2, _Rp>*);
41227825Stheravenpublic:
42227825Stheraven    static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
43227825Stheraven    typedef decltype(__test((_Tp*)0)) type;
44227825Stheraven};
45227825Stheraven
46227825Stheraventemplate <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
47227825Stheravenstruct __maybe_derive_from_unary_function  // bool is true
48227825Stheraven    : public __derives_from_unary_function<_Tp>::type
49227825Stheraven{
50227825Stheraven};
51227825Stheraven
52227825Stheraventemplate <class _Tp>
53227825Stheravenstruct __maybe_derive_from_unary_function<_Tp, false>
54227825Stheraven{
55227825Stheraven};
56227825Stheraven
57227825Stheraventemplate <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
58227825Stheravenstruct __maybe_derive_from_binary_function  // bool is true
59227825Stheraven    : public __derives_from_binary_function<_Tp>::type
60227825Stheraven{
61227825Stheraven};
62227825Stheraven
63227825Stheraventemplate <class _Tp>
64227825Stheravenstruct __maybe_derive_from_binary_function<_Tp, false>
65227825Stheraven{
66227825Stheraven};
67227825Stheraven
68227825Stheraventemplate <class _Tp, bool = __has_result_type<_Tp>::value>
69227825Stheravenstruct __weak_result_type_imp // bool is true
70227825Stheraven    : public __maybe_derive_from_unary_function<_Tp>,
71227825Stheraven      public __maybe_derive_from_binary_function<_Tp>
72227825Stheraven{
73227825Stheraven    typedef typename _Tp::result_type result_type;
74227825Stheraven};
75227825Stheraven
76227825Stheraventemplate <class _Tp>
77227825Stheravenstruct __weak_result_type_imp<_Tp, false>
78227825Stheraven    : public __maybe_derive_from_unary_function<_Tp>,
79227825Stheraven      public __maybe_derive_from_binary_function<_Tp>
80227825Stheraven{
81227825Stheraven};
82227825Stheraven
83227825Stheraventemplate <class _Tp>
84227825Stheravenstruct __weak_result_type
85227825Stheraven    : public __weak_result_type_imp<typename remove_reference<_Tp>::type>
86227825Stheraven{
87227825Stheraven};
88227825Stheraven
89227825Stheraven// 0 argument case
90227825Stheraven
91232950Stheraventemplate <class _Rp>
92232950Stheravenstruct __weak_result_type<_Rp ()>
93227825Stheraven{
94232950Stheraven    typedef _Rp result_type;
95227825Stheraven};
96227825Stheraven
97232950Stheraventemplate <class _Rp>
98232950Stheravenstruct __weak_result_type<_Rp (&)()>
99227825Stheraven{
100232950Stheraven    typedef _Rp result_type;
101227825Stheraven};
102227825Stheraven
103232950Stheraventemplate <class _Rp>
104232950Stheravenstruct __weak_result_type<_Rp (*)()>
105227825Stheraven{
106232950Stheraven    typedef _Rp result_type;
107227825Stheraven};
108227825Stheraven
109227825Stheraven// 1 argument case
110227825Stheraven
111232950Stheraventemplate <class _Rp, class _A1>
112232950Stheravenstruct __weak_result_type<_Rp (_A1)>
113232950Stheraven    : public unary_function<_A1, _Rp>
114227825Stheraven{
115227825Stheraven};
116227825Stheraven
117232950Stheraventemplate <class _Rp, class _A1>
118232950Stheravenstruct __weak_result_type<_Rp (&)(_A1)>
119232950Stheraven    : public unary_function<_A1, _Rp>
120227825Stheraven{
121227825Stheraven};
122227825Stheraven
123232950Stheraventemplate <class _Rp, class _A1>
124232950Stheravenstruct __weak_result_type<_Rp (*)(_A1)>
125232950Stheraven    : public unary_function<_A1, _Rp>
126227825Stheraven{
127227825Stheraven};
128227825Stheraven
129232950Stheraventemplate <class _Rp, class _Cp>
130232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)()>
131232950Stheraven    : public unary_function<_Cp*, _Rp>
132227825Stheraven{
133227825Stheraven};
134227825Stheraven
135232950Stheraventemplate <class _Rp, class _Cp>
136232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)() const>
137232950Stheraven    : public unary_function<const _Cp*, _Rp>
138227825Stheraven{
139227825Stheraven};
140227825Stheraven
141232950Stheraventemplate <class _Rp, class _Cp>
142232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)() volatile>
143232950Stheraven    : public unary_function<volatile _Cp*, _Rp>
144227825Stheraven{
145227825Stheraven};
146227825Stheraven
147232950Stheraventemplate <class _Rp, class _Cp>
148232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)() const volatile>
149232950Stheraven    : public unary_function<const volatile _Cp*, _Rp>
150227825Stheraven{
151227825Stheraven};
152227825Stheraven
153227825Stheraven// 2 argument case
154227825Stheraven
155232950Stheraventemplate <class _Rp, class _A1, class _A2>
156232950Stheravenstruct __weak_result_type<_Rp (_A1, _A2)>
157232950Stheraven    : public binary_function<_A1, _A2, _Rp>
158227825Stheraven{
159227825Stheraven};
160227825Stheraven
161232950Stheraventemplate <class _Rp, class _A1, class _A2>
162232950Stheravenstruct __weak_result_type<_Rp (*)(_A1, _A2)>
163232950Stheraven    : public binary_function<_A1, _A2, _Rp>
164227825Stheraven{
165227825Stheraven};
166227825Stheraven
167232950Stheraventemplate <class _Rp, class _A1, class _A2>
168232950Stheravenstruct __weak_result_type<_Rp (&)(_A1, _A2)>
169232950Stheraven    : public binary_function<_A1, _A2, _Rp>
170227825Stheraven{
171227825Stheraven};
172227825Stheraven
173232950Stheraventemplate <class _Rp, class _Cp, class _A1>
174232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1)>
175232950Stheraven    : public binary_function<_Cp*, _A1, _Rp>
176227825Stheraven{
177227825Stheraven};
178227825Stheraven
179232950Stheraventemplate <class _Rp, class _Cp, class _A1>
180232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1) const>
181232950Stheraven    : public binary_function<const _Cp*, _A1, _Rp>
182227825Stheraven{
183227825Stheraven};
184227825Stheraven
185232950Stheraventemplate <class _Rp, class _Cp, class _A1>
186232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
187232950Stheraven    : public binary_function<volatile _Cp*, _A1, _Rp>
188227825Stheraven{
189227825Stheraven};
190227825Stheraven
191232950Stheraventemplate <class _Rp, class _Cp, class _A1>
192232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
193232950Stheraven    : public binary_function<const volatile _Cp*, _A1, _Rp>
194227825Stheraven{
195227825Stheraven};
196227825Stheraven
197227825Stheraven// 3 or more arguments
198227825Stheraven
199232950Stheraventemplate <class _Rp, class _A1, class _A2, class _A3>
200232950Stheravenstruct __weak_result_type<_Rp (_A1, _A2, _A3)>
201227825Stheraven{
202232950Stheraven    typedef _Rp result_type;
203227825Stheraven};
204227825Stheraven
205232950Stheraventemplate <class _Rp, class _A1, class _A2, class _A3>
206232950Stheravenstruct __weak_result_type<_Rp (&)(_A1, _A2, _A3)>
207227825Stheraven{
208232950Stheraven    typedef _Rp result_type;
209227825Stheraven};
210227825Stheraven
211232950Stheraventemplate <class _Rp, class _A1, class _A2, class _A3>
212232950Stheravenstruct __weak_result_type<_Rp (*)(_A1, _A2, _A3)>
213227825Stheraven{
214232950Stheraven    typedef _Rp result_type;
215227825Stheraven};
216227825Stheraven
217232950Stheraventemplate <class _Rp, class _Cp, class _A1, class _A2>
218232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1, _A2)>
219227825Stheraven{
220232950Stheraven    typedef _Rp result_type;
221227825Stheraven};
222227825Stheraven
223232950Stheraventemplate <class _Rp, class _Cp, class _A1, class _A2>
224232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) const>
225227825Stheraven{
226232950Stheraven    typedef _Rp result_type;
227227825Stheraven};
228227825Stheraven
229232950Stheraventemplate <class _Rp, class _Cp, class _A1, class _A2>
230232950Stheravenstruct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) volatile>
231227825Stheraven{
232232950Stheraven    typedef _Rp result_type;
233227825Stheraven};
234227825Stheraven
235227825Stheraven// __invoke
236227825Stheraven
237227825Stheraven// __ref_return0
238227825Stheraven//
239227825Stheraven// template <class _Tp, bool _HasResultType>
240227825Stheraven// struct ________ref_return0  // _HasResultType is true
241227825Stheraven// {
242227825Stheraven//     typedef typename _Tp::result_type type;
243227825Stheraven// };
244227825Stheraven//
245227825Stheraven// template <class _Tp>
246227825Stheraven// struct ________ref_return0<_Tp, false>
247227825Stheraven// {
248227825Stheraven//     typedef void type;
249227825Stheraven// };
250227825Stheraven//
251227825Stheraven// template <class _Tp, bool _IsClass>
252227825Stheraven// struct ____ref_return0  // _IsClass is true
253227825Stheraven//     : public ________ref_return0<_Tp, __has_result_type<typename remove_cv<_Tp>::type>::value>
254227825Stheraven// {
255227825Stheraven// };
256227825Stheraven//
257227825Stheraven// template <class _Tp, bool _HasResultType>
258227825Stheraven// struct ______ref_return0  // _HasResultType is true
259227825Stheraven// {
260227825Stheraven//     typedef typename __callable_type<_Tp>::result_type type;
261227825Stheraven// };
262227825Stheraven//
263227825Stheraven// template <class _Tp>
264227825Stheraven// struct ______ref_return0<_Tp, false>  // pointer to member data
265227825Stheraven// {
266227825Stheraven//     typedef void type;
267227825Stheraven// };
268227825Stheraven//
269227825Stheraven// template <class _Tp>
270227825Stheraven// struct ____ref_return0<_Tp, false>
271227825Stheraven//     : public ______ref_return0<typename remove_cv<_Tp>::type,
272227825Stheraven//                  __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value>
273227825Stheraven// {
274227825Stheraven// };
275227825Stheraven//
276227825Stheraven// template <class _Tp>
277227825Stheraven// struct __ref_return0
278227825Stheraven//     : public ____ref_return0<typename remove_reference<_Tp>::type,
279227825Stheraven//                    is_class<typename remove_reference<_Tp>::type>::value>
280227825Stheraven// {
281227825Stheraven// };
282227825Stheraven//
283227825Stheraven// __ref_return1
284227825Stheraven//
285227825Stheraven// template <class _Tp, bool _IsClass, class _A0>
286227825Stheraven// struct ____ref_return1  // _IsClass is true
287227825Stheraven// {
288227825Stheraven//     typedef typename result_of<_Tp(_A0)>::type type;
289227825Stheraven// };
290227825Stheraven//
291227825Stheraven// template <class _Tp, bool _HasResultType, class _A0>
292227825Stheraven// struct ______ref_return1  // _HasResultType is true
293227825Stheraven// {
294227825Stheraven//     typedef typename __callable_type<_Tp>::result_type type;
295227825Stheraven// };
296227825Stheraven//
297227825Stheraven// template <class _Tp, class _A0, bool>
298227825Stheraven// struct __ref_return1_member_data1;
299227825Stheraven//
300232950Stheraven// template <class _Rp, class _Cp, class _A0>
301232950Stheraven// struct __ref_return1_member_data1<_Rp _Cp::*, _A0, true>
302227825Stheraven// {
303232950Stheraven//     typedef typename __apply_cv<_A0, _Rp>::type& type;
304227825Stheraven// };
305227825Stheraven//
306232950Stheraven// template <class _Rp, class _Cp, class _A0>
307232950Stheraven// struct __ref_return1_member_data1<_Rp _Cp::*, _A0, false>
308227825Stheraven// {
309227825Stheraven//     static _A0 __a;
310232950Stheraven//     typedef typename __apply_cv<decltype(*__a), _Rp>::type& type;
311227825Stheraven// };
312227825Stheraven//
313227825Stheraven// template <class _Tp, class _A0>
314227825Stheraven// struct __ref_return1_member_data;
315227825Stheraven//
316232950Stheraven// template <class _Rp, class _Cp, class _A0>
317232950Stheraven// struct __ref_return1_member_data<_Rp _Cp::*, _A0>
318232950Stheraven//     : public __ref_return1_member_data1<_Rp _Cp::*, _A0,
319232950Stheraven//                 is_same<typename remove_cv<_Cp>::type,
320227825Stheraven//                         typename remove_cv<typename remove_reference<_A0>::type>::type>::value>
321227825Stheraven// {
322227825Stheraven// };
323227825Stheraven//
324227825Stheraven// template <class _Tp, class _A0>
325227825Stheraven// struct ______ref_return1<_Tp, false, _A0>  // pointer to member data
326227825Stheraven//     : public __ref_return1_member_data<typename remove_cv<_Tp>::type, _A0>
327227825Stheraven// {
328227825Stheraven// };
329227825Stheraven//
330227825Stheraven// template <class _Tp, class _A0>
331227825Stheraven// struct ____ref_return1<_Tp, false, _A0>
332227825Stheraven//     : public ______ref_return1<typename remove_cv<_Tp>::type,
333227825Stheraven//                  __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0>
334227825Stheraven// {
335227825Stheraven// };
336227825Stheraven//
337227825Stheraven// template <class _Tp, class _A0>
338227825Stheraven// struct __ref_return1
339227825Stheraven//     : public ____ref_return1<typename remove_reference<_Tp>::type,
340227825Stheraven//                    is_class<typename remove_reference<_Tp>::type>::value, _A0>
341227825Stheraven// {
342227825Stheraven// };
343227825Stheraven//
344227825Stheraven// __ref_return2
345227825Stheraven//
346227825Stheraven// template <class _Tp, bool _IsClass, class _A0, class _A1>
347227825Stheraven// struct ____ref_return2  // _IsClass is true
348227825Stheraven// {
349227825Stheraven//     typedef typename result_of<_Tp(_A0, _A1)>::type type;
350227825Stheraven// };
351227825Stheraven//
352227825Stheraven// template <class _Tp, bool _HasResultType, class _A0, class _A1>
353227825Stheraven// struct ______ref_return2  // _HasResultType is true
354227825Stheraven// {
355227825Stheraven//     typedef typename __callable_type<_Tp>::result_type type;
356227825Stheraven// };
357227825Stheraven//
358227825Stheraven// template <class _Tp>
359227825Stheraven// struct ______ref_return2<_Tp, false, class _A0, class _A1>  // pointer to member data
360227825Stheraven// {
361227825Stheraven//     static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer"
362227825Stheraven//                          " to member data with too many arguments.");
363227825Stheraven// };
364227825Stheraven//
365227825Stheraven// template <class _Tp, class _A0, class _A1>
366227825Stheraven// struct ____ref_return2<_Tp, false, _A0, _A1>
367227825Stheraven//     : public ______ref_return2<typename remove_cv<_Tp>::type,
368227825Stheraven//                  __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0, _A1>
369227825Stheraven// {
370227825Stheraven// };
371227825Stheraven//
372227825Stheraven// template <class _Tp, class _A0, class _A1>
373227825Stheraven// struct __ref_return2
374227825Stheraven//     : public ____ref_return2<typename remove_reference<_Tp>::type,
375227825Stheraven//                    is_class<typename remove_reference<_Tp>::type>::value, _A0, _A1>
376227825Stheraven// {
377227825Stheraven// };
378227825Stheraven//
379227825Stheraven// __ref_return3
380227825Stheraven//
381227825Stheraven// template <class _Tp, bool _IsClass, class _A0, class _A1, class _A2>
382227825Stheraven// struct ____ref_return3  // _IsClass is true
383227825Stheraven// {
384227825Stheraven//     typedef typename result_of<_Tp(_A0, _A1, _A2)>::type type;
385227825Stheraven// };
386227825Stheraven//
387227825Stheraven// template <class _Tp, bool _HasResultType, class _A0, class _A1, class _A2>
388227825Stheraven// struct ______ref_return3  // _HasResultType is true
389227825Stheraven// {
390227825Stheraven//     typedef typename __callable_type<_Tp>::result_type type;
391227825Stheraven// };
392227825Stheraven//
393227825Stheraven// template <class _Tp>
394227825Stheraven// struct ______ref_return3<_Tp, false, class _A0, class _A1, class _A2>  // pointer to member data
395227825Stheraven// {
396227825Stheraven//     static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer"
397227825Stheraven//                          " to member data with too many arguments.");
398227825Stheraven// };
399227825Stheraven//
400227825Stheraven// template <class _Tp, class _A0, class _A1, class _A2>
401227825Stheraven// struct ____ref_return3<_Tp, false, _A0, _A1, _A2>
402227825Stheraven//     : public ______ref_return3<typename remove_cv<_Tp>::type,
403227825Stheraven//                  __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0, _A1, _A2>
404227825Stheraven// {
405227825Stheraven// };
406227825Stheraven//
407227825Stheraven// template <class _Tp, class _A0, class _A1, class _A2>
408227825Stheraven// struct __ref_return3
409227825Stheraven//     : public ____ref_return3<typename remove_reference<_Tp>::type,
410227825Stheraven//                    is_class<typename remove_reference<_Tp>::type>::value, _A0, _A1, _A2>
411227825Stheraven// {
412227825Stheraven// };
413227825Stheraven
414227825Stheraven// first bullet
415227825Stheraven
416232950Stheraventemplate <class _Rp, class _Tp, class _T1>
417227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
418227825Stheraventypename enable_if
419227825Stheraven<
420232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
421232950Stheraven    _Rp
422227825Stheraven>::type
423232950Stheraven__invoke(_Rp (_Tp::*__f)(), _T1& __t1)
424227825Stheraven{
425227825Stheraven    return (__t1.*__f)();
426227825Stheraven}
427227825Stheraven
428232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0>
429227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
430227825Stheraventypename enable_if
431227825Stheraven<
432232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
433232950Stheraven    _Rp
434227825Stheraven>::type
435232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0), _T1& __t1, _A0& __a0)
436227825Stheraven{
437227825Stheraven    return (__t1.*__f)(__a0);
438227825Stheraven}
439227825Stheraven
440232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1>
441227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
442227825Stheraventypename enable_if
443227825Stheraven<
444232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
445232950Stheraven    _Rp
446227825Stheraven>::type
447232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1& __t1, _A0& __a0, _A1& __a1)
448227825Stheraven{
449227825Stheraven    return (__t1.*__f)(__a0, __a1);
450227825Stheraven}
451227825Stheraven
452232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
453227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
454227825Stheraventypename enable_if
455227825Stheraven<
456232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
457232950Stheraven    _Rp
458227825Stheraven>::type
459232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
460227825Stheraven{
461227825Stheraven    return (__t1.*__f)(__a0, __a1, __a2);
462227825Stheraven}
463227825Stheraven
464232950Stheraventemplate <class _Rp, class _Tp, class _T1>
465227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
466227825Stheraventypename enable_if
467227825Stheraven<
468232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
469232950Stheraven    _Rp
470227825Stheraven>::type
471232950Stheraven__invoke(_Rp (_Tp::*__f)() const, _T1& __t1)
472227825Stheraven{
473227825Stheraven    return (__t1.*__f)();
474227825Stheraven}
475227825Stheraven
476232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0>
477227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
478227825Stheraventypename enable_if
479227825Stheraven<
480232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
481232950Stheraven    _Rp
482227825Stheraven>::type
483232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0) const, _T1& __t1, _A0& __a0)
484227825Stheraven{
485227825Stheraven    return (__t1.*__f)(__a0);
486227825Stheraven}
487227825Stheraven
488232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1>
489227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
490227825Stheraventypename enable_if
491227825Stheraven<
492232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
493232950Stheraven    _Rp
494227825Stheraven>::type
495232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1& __t1, _A0& __a0, _A1& __a1)
496227825Stheraven{
497227825Stheraven    return (__t1.*__f)(__a0, __a1);
498227825Stheraven}
499227825Stheraven
500232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
501227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
502227825Stheraventypename enable_if
503227825Stheraven<
504232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
505232950Stheraven    _Rp
506227825Stheraven>::type
507232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
508227825Stheraven{
509227825Stheraven    return (__t1.*__f)(__a0, __a1, __a2);
510227825Stheraven}
511227825Stheraven
512232950Stheraventemplate <class _Rp, class _Tp, class _T1>
513227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
514227825Stheraventypename enable_if
515227825Stheraven<
516232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
517232950Stheraven    _Rp
518227825Stheraven>::type
519232950Stheraven__invoke(_Rp (_Tp::*__f)() volatile, _T1& __t1)
520227825Stheraven{
521227825Stheraven    return (__t1.*__f)();
522227825Stheraven}
523227825Stheraven
524232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0>
525227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
526227825Stheraventypename enable_if
527227825Stheraven<
528232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
529232950Stheraven    _Rp
530227825Stheraven>::type
531232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1& __t1, _A0& __a0)
532227825Stheraven{
533227825Stheraven    return (__t1.*__f)(__a0);
534227825Stheraven}
535227825Stheraven
536232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1>
537227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
538227825Stheraventypename enable_if
539227825Stheraven<
540232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
541232950Stheraven    _Rp
542227825Stheraven>::type
543232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1& __t1, _A0& __a0, _A1& __a1)
544227825Stheraven{
545227825Stheraven    return (__t1.*__f)(__a0, __a1);
546227825Stheraven}
547227825Stheraven
548232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
549227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
550227825Stheraventypename enable_if
551227825Stheraven<
552232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
553232950Stheraven    _Rp
554227825Stheraven>::type
555232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
556227825Stheraven{
557227825Stheraven    return (__t1.*__f)(__a0, __a1, __a2);
558227825Stheraven}
559227825Stheraven
560232950Stheraventemplate <class _Rp, class _Tp, class _T1>
561227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
562227825Stheraventypename enable_if
563227825Stheraven<
564232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
565232950Stheraven    _Rp
566227825Stheraven>::type
567232950Stheraven__invoke(_Rp (_Tp::*__f)() const volatile, _T1& __t1)
568227825Stheraven{
569227825Stheraven    return (__t1.*__f)();
570227825Stheraven}
571227825Stheraven
572232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0>
573227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
574227825Stheraventypename enable_if
575227825Stheraven<
576232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
577232950Stheraven    _Rp
578227825Stheraven>::type
579232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1& __t1, _A0& __a0)
580227825Stheraven{
581227825Stheraven    return (__t1.*__f)(__a0);
582227825Stheraven}
583227825Stheraven
584232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1>
585227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
586227825Stheraventypename enable_if
587227825Stheraven<
588232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
589232950Stheraven    _Rp
590227825Stheraven>::type
591232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1& __t1, _A0& __a0, _A1& __a1)
592227825Stheraven{
593227825Stheraven    return (__t1.*__f)(__a0, __a1);
594227825Stheraven}
595227825Stheraven
596232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
597227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
598227825Stheraventypename enable_if
599227825Stheraven<
600232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
601232950Stheraven    _Rp
602227825Stheraven>::type
603232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
604227825Stheraven{
605227825Stheraven    return (__t1.*__f)(__a0, __a1, __a2);
606227825Stheraven}
607227825Stheraven
608227825Stheraven// second bullet
609227825Stheraven
610232950Stheraventemplate <class _Rp, class _Tp, class _T1>
611227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
612227825Stheraventypename enable_if
613227825Stheraven<
614232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
615232950Stheraven    _Rp
616227825Stheraven>::type
617232950Stheraven__invoke(_Rp (_Tp::*__f)(), _T1 __t1)
618227825Stheraven{
619227825Stheraven    return ((*__t1).*__f)();
620227825Stheraven}
621227825Stheraven
622232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0>
623227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
624227825Stheraventypename enable_if
625227825Stheraven<
626232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
627232950Stheraven    _Rp
628227825Stheraven>::type
629232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0), _T1 __t1, _A0& __a0)
630227825Stheraven{
631227825Stheraven    return ((*__t1).*__f)(__a0);
632227825Stheraven}
633227825Stheraven
634232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1>
635227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
636227825Stheraventypename enable_if
637227825Stheraven<
638232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
639232950Stheraven    _Rp
640227825Stheraven>::type
641232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1 __t1, _A0& __a0, _A1& __a1)
642227825Stheraven{
643227825Stheraven    return ((*__t1).*__f)(__a0, __a1);
644227825Stheraven}
645227825Stheraven
646232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
647227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
648227825Stheraventypename enable_if
649227825Stheraven<
650232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
651232950Stheraven    _Rp
652227825Stheraven>::type
653232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
654227825Stheraven{
655227825Stheraven    return ((*__t1).*__f)(__a0, __a1, __a2);
656227825Stheraven}
657227825Stheraven
658232950Stheraventemplate <class _Rp, class _Tp, class _T1>
659227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
660227825Stheraventypename enable_if
661227825Stheraven<
662232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
663232950Stheraven    _Rp
664227825Stheraven>::type
665232950Stheraven__invoke(_Rp (_Tp::*__f)() const, _T1 __t1)
666227825Stheraven{
667227825Stheraven    return ((*__t1).*__f)();
668227825Stheraven}
669227825Stheraven
670232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0>
671227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
672227825Stheraventypename enable_if
673227825Stheraven<
674232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
675232950Stheraven    _Rp
676227825Stheraven>::type
677232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0) const, _T1 __t1, _A0& __a0)
678227825Stheraven{
679227825Stheraven    return ((*__t1).*__f)(__a0);
680227825Stheraven}
681227825Stheraven
682232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1>
683227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
684227825Stheraventypename enable_if
685227825Stheraven<
686232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
687232950Stheraven    _Rp
688227825Stheraven>::type
689232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1 __t1, _A0& __a0, _A1& __a1)
690227825Stheraven{
691227825Stheraven    return ((*__t1).*__f)(__a0, __a1);
692227825Stheraven}
693227825Stheraven
694232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
695227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
696227825Stheraventypename enable_if
697227825Stheraven<
698232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
699232950Stheraven    _Rp
700227825Stheraven>::type
701232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
702227825Stheraven{
703227825Stheraven    return ((*__t1).*__f)(__a0, __a1, __a2);
704227825Stheraven}
705227825Stheraven
706232950Stheraventemplate <class _Rp, class _Tp, class _T1>
707227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
708227825Stheraventypename enable_if
709227825Stheraven<
710232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
711232950Stheraven    _Rp
712227825Stheraven>::type
713232950Stheraven__invoke(_Rp (_Tp::*__f)() volatile, _T1 __t1)
714227825Stheraven{
715227825Stheraven    return ((*__t1).*__f)();
716227825Stheraven}
717227825Stheraven
718232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0>
719227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
720227825Stheraventypename enable_if
721227825Stheraven<
722232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
723232950Stheraven    _Rp
724227825Stheraven>::type
725232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1 __t1, _A0& __a0)
726227825Stheraven{
727227825Stheraven    return ((*__t1).*__f)(__a0);
728227825Stheraven}
729227825Stheraven
730232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1>
731227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
732227825Stheraventypename enable_if
733227825Stheraven<
734232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
735232950Stheraven    _Rp
736227825Stheraven>::type
737232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1 __t1, _A0& __a0, _A1& __a1)
738227825Stheraven{
739227825Stheraven    return ((*__t1).*__f)(__a0, __a1);
740227825Stheraven}
741227825Stheraven
742232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
743227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
744227825Stheraventypename enable_if
745227825Stheraven<
746232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
747232950Stheraven    _Rp
748227825Stheraven>::type
749232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
750227825Stheraven{
751227825Stheraven    return ((*__t1).*__f)(__a0, __a1, __a2);
752227825Stheraven}
753227825Stheraven
754232950Stheraventemplate <class _Rp, class _Tp, class _T1>
755227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
756227825Stheraventypename enable_if
757227825Stheraven<
758232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
759232950Stheraven    _Rp
760227825Stheraven>::type
761232950Stheraven__invoke(_Rp (_Tp::*__f)() const volatile, _T1 __t1)
762227825Stheraven{
763227825Stheraven    return ((*__t1).*__f)();
764227825Stheraven}
765227825Stheraven
766232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0>
767227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
768227825Stheraventypename enable_if
769227825Stheraven<
770232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
771232950Stheraven    _Rp
772227825Stheraven>::type
773232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1 __t1, _A0& __a0)
774227825Stheraven{
775227825Stheraven    return ((*__t1).*__f)(__a0);
776227825Stheraven}
777227825Stheraven
778232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1>
779227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
780227825Stheraventypename enable_if
781227825Stheraven<
782232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
783232950Stheraven    _Rp
784227825Stheraven>::type
785232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1 __t1, _A0& __a0, _A1& __a1)
786227825Stheraven{
787227825Stheraven    return ((*__t1).*__f)(__a0, __a1);
788227825Stheraven}
789227825Stheraven
790232950Stheraventemplate <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
791227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
792227825Stheraventypename enable_if
793227825Stheraven<
794232950Stheraven    !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
795232950Stheraven    _Rp
796227825Stheraven>::type
797232950Stheraven__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
798227825Stheraven{
799227825Stheraven    return ((*__t1).*__f)(__a0, __a1, __a2);
800227825Stheraven}
801227825Stheraven
802227825Stheraven// third bullet
803227825Stheraven
804232950Stheraventemplate <class _Rp, class _Tp, class _T1>
805227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
806227825Stheraventypename enable_if
807227825Stheraven<
808232950Stheraven    is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
809232950Stheraven    typename __apply_cv<_T1, _Rp>::type&
810227825Stheraven>::type
811232950Stheraven__invoke(_Rp _Tp::* __f, _T1& __t1)
812227825Stheraven{
813227825Stheraven    return __t1.*__f;
814227825Stheraven}
815227825Stheraven
816232950Stheraventemplate <class _Rp, class _Tp>
817227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
818227825Stheravenvoid
819232950Stheraven__invoke(_Rp _Tp::*)
820227825Stheraven{
821227825Stheraven}
822227825Stheraven
823232950Stheraven// template <class _Dp, class _Rp, class _Tp, class _T1>
824227825Stheraven// inline _LIBCPP_INLINE_VISIBILITY
825227825Stheraven// typename enable_if
826227825Stheraven// <
827232950Stheraven//     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
828232950Stheraven//     typename __ref_return1<_Rp _Tp::*, _T1>::type
829227825Stheraven// >::type
830232950Stheraven// __invoke(_Rp _Tp::* __f, _T1& __t1)
831227825Stheraven// {
832227825Stheraven//     return __t1.*__f;
833227825Stheraven// }
834227825Stheraven
835227825Stheraven// forth bullet
836227825Stheraven
837232950Stheraventemplate <class _T1, class _Rp, bool>
838227825Stheravenstruct __4th_helper
839227825Stheraven{
840227825Stheraven};
841227825Stheraven
842232950Stheraventemplate <class _T1, class _Rp>
843232950Stheravenstruct __4th_helper<_T1, _Rp, true>
844227825Stheraven{
845232950Stheraven    typedef typename __apply_cv<decltype(*_VSTD::declval<_T1>()), _Rp>::type type;
846227825Stheraven};
847227825Stheraven
848232950Stheraventemplate <class _Rp, class _Tp, class _T1>
849227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
850232950Stheraventypename __4th_helper<_T1, _Rp,
851232950Stheraven                      !is_base_of<_Tp,
852227825Stheraven                                  typename remove_reference<_T1>::type
853227825Stheraven                                 >::value
854227825Stheraven                     >::type&
855232950Stheraven__invoke(_Rp _Tp::* __f, _T1& __t1)
856227825Stheraven{
857227825Stheraven    return (*__t1).*__f;
858227825Stheraven}
859227825Stheraven
860232950Stheraven// template <class _Dp, class _Rp, class _Tp, class _T1>
861227825Stheraven// inline _LIBCPP_INLINE_VISIBILITY
862227825Stheraven// typename enable_if
863227825Stheraven// <
864232950Stheraven//     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
865232950Stheraven//     typename __ref_return1<_Rp _Tp::*, _T1>::type
866227825Stheraven// >::type
867232950Stheraven// __invoke(_Rp _Tp::* __f, _T1 __t1)
868227825Stheraven// {
869227825Stheraven//     return (*__t1).*__f;
870227825Stheraven// }
871227825Stheraven
872227825Stheraven// fifth bullet
873227825Stheraven
874232950Stheraventemplate <class _Fp>
875227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
876232950Stheravendecltype(declval<_Fp>()())
877232950Stheraven__invoke(_Fp __f)
878227825Stheraven{
879227825Stheraven    return __f();
880227825Stheraven}
881227825Stheraven
882232950Stheraventemplate <class _Fp, class _A0>
883227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
884232950Stheravendecltype(declval<_Fp>()(declval<_A0&>()))
885232950Stheraven__invoke(_Fp __f, _A0& __a0)
886227825Stheraven{
887227825Stheraven    return __f(__a0);
888227825Stheraven}
889227825Stheraven
890232950Stheraventemplate <class _Fp, class _A0, class _A1>
891227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
892232950Stheravendecltype(declval<_Fp>()(declval<_A0&>(), declval<_A1&>()))
893232950Stheraven__invoke(_Fp __f, _A0& __a0, _A1& __a1)
894227825Stheraven{
895227825Stheraven    return __f(__a0, __a1);
896227825Stheraven}
897227825Stheraven
898232950Stheraventemplate <class _Fp, class _A0, class _A1, class _A2>
899227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
900232950Stheravendecltype(declval<_Fp>()(declval<_A0&>(), declval<_A1&>(), declval<_A2&>()))
901232950Stheraven__invoke(_Fp __f, _A0& __a0, _A1& __a1, _A2& __a2)
902227825Stheraven{
903227825Stheraven    return __f(__a0, __a1, __a2);
904227825Stheraven}
905227825Stheraven
906232950Stheraven// template <class _Rp, class _Fp>
907227825Stheraven// inline _LIBCPP_INLINE_VISIBILITY
908232950Stheraven// _Rp
909232950Stheraven// __invoke(_Fp& __f)
910227825Stheraven// {
911227825Stheraven//     return __f();
912227825Stheraven// }
913227825Stheraven//
914232950Stheraven// template <class _Rp, class _Fp, class _A0>
915227825Stheraven// inline _LIBCPP_INLINE_VISIBILITY
916227825Stheraven// typename enable_if
917227825Stheraven// <
918232950Stheraven//     !is_member_pointer<_Fp>::value,
919232950Stheraven//     _Rp
920227825Stheraven// >::type
921232950Stheraven// __invoke(_Fp& __f, _A0& __a0)
922227825Stheraven// {
923227825Stheraven//     return __f(__a0);
924227825Stheraven// }
925227825Stheraven//
926232950Stheraven// template <class _Rp, class _Fp, class _A0, class _A1>
927227825Stheraven// inline _LIBCPP_INLINE_VISIBILITY
928232950Stheraven// _Rp
929232950Stheraven// __invoke(_Fp& __f, _A0& __a0, _A1& __a1)
930227825Stheraven// {
931227825Stheraven//     return __f(__a0, __a1);
932227825Stheraven// }
933227825Stheraven//
934232950Stheraven// template <class _Rp, class _Fp, class _A0, class _A1, class _A2>
935227825Stheraven// inline _LIBCPP_INLINE_VISIBILITY
936232950Stheraven// _Rp
937232950Stheraven// __invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2)
938227825Stheraven// {
939227825Stheraven//     return __f(__a0, __a1, __a2);
940227825Stheraven// }
941227825Stheraven
942227825Stheraventemplate <class _Tp>
943227825Stheravenstruct __has_type
944227825Stheraven{
945227825Stheravenprivate:
946242945Stheraven    struct __two {char __lx; char __lxx;};
947227825Stheraven    template <class _Up> static __two __test(...);
948227825Stheraven    template <class _Up> static char __test(typename _Up::type* = 0);
949227825Stheravenpublic:
950227825Stheraven    static const bool value = sizeof(__test<_Tp>(0)) == 1;
951227825Stheraven};
952227825Stheraven
953232950Stheraventemplate <class _Fp, bool = __has_result_type<__weak_result_type<_Fp> >::value>
954227825Stheravenstruct __invoke_return
955227825Stheraven{
956232950Stheraven    typedef typename __weak_result_type<_Fp>::result_type type;
957227825Stheraven};
958227825Stheraven
959232950Stheraventemplate <class _Fp>
960232950Stheravenstruct __invoke_return<_Fp, false>
961227825Stheraven{
962232950Stheraven    typedef decltype(__invoke(_VSTD::declval<_Fp>())) type;
963227825Stheraven};
964227825Stheraven
965227825Stheraventemplate <class _Tp, class _A0>
966227825Stheravenstruct __invoke_return0
967227825Stheraven{
968227825Stheraven    typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>())) type;
969227825Stheraven};
970227825Stheraven
971232950Stheraventemplate <class _Rp, class _Tp, class _A0>
972232950Stheravenstruct __invoke_return0<_Rp _Tp::*, _A0>
973227825Stheraven{
974232950Stheraven    typedef typename __apply_cv<_A0, _Rp>::type& type;
975227825Stheraven};
976227825Stheraven
977232950Stheraventemplate <class _Rp, class _Tp, class _A0>
978232950Stheravenstruct __invoke_return0<_Rp _Tp::*, _A0*>
979227825Stheraven{
980232950Stheraven    typedef typename __apply_cv<_A0, _Rp>::type& type;
981227825Stheraven};
982227825Stheraven
983227825Stheraventemplate <class _Tp, class _A0, class _A1>
984227825Stheravenstruct __invoke_return1
985227825Stheraven{
986227825Stheraven    typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(),
987227825Stheraven                                                    _VSTD::declval<_A1>())) type;
988227825Stheraven};
989227825Stheraven
990227825Stheraventemplate <class _Tp, class _A0, class _A1, class _A2>
991227825Stheravenstruct __invoke_return2
992227825Stheraven{
993227825Stheraven    typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(),
994227825Stheraven                                                    _VSTD::declval<_A1>(),
995227825Stheraven                                                    _VSTD::declval<_A2>())) type;
996227825Stheraven};
997227825Stheraven
998308143Sdimtemplate <class _Ret>
999308143Sdimstruct __invoke_void_return_wrapper
1000308143Sdim{
1001308143Sdim    template <class _Fn>
1002308143Sdim    static _Ret __call(_Fn __f)
1003308143Sdim    {
1004308143Sdim        return __invoke(__f);
1005308143Sdim    }
1006308143Sdim
1007308143Sdim    template <class _Fn, class _A0>
1008308143Sdim    static _Ret __call(_Fn __f, _A0& __a0)
1009308143Sdim    {
1010308143Sdim        return __invoke(__f, __a0);
1011308143Sdim    }
1012308143Sdim
1013308143Sdim    template <class _Fn, class _A0, class _A1>
1014308143Sdim    static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1)
1015308143Sdim    {
1016308143Sdim        return __invoke(__f, __a0, __a1);
1017308143Sdim    }
1018308143Sdim
1019308143Sdim    template <class _Fn, class _A0, class _A1, class _A2>
1020308143Sdim    static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2)
1021308143Sdim    {
1022308143Sdim        return __invoke(__f, __a0, __a1, __a2);
1023308143Sdim    }
1024308143Sdim};
1025308143Sdim
1026308143Sdim
1027308143Sdimtemplate <>
1028308143Sdimstruct __invoke_void_return_wrapper<void>
1029308143Sdim{
1030308143Sdim    template <class _Fn>
1031308143Sdim    static void __call(_Fn __f)
1032308143Sdim    {
1033308143Sdim        __invoke(__f);
1034308143Sdim    }
1035308143Sdim
1036308143Sdim    template <class _Fn, class _A0>
1037308143Sdim    static void __call(_Fn __f, _A0& __a0)
1038308143Sdim    {
1039308143Sdim        __invoke(__f, __a0);
1040308143Sdim    }
1041308143Sdim
1042308143Sdim    template <class _Fn, class _A0, class _A1>
1043308143Sdim    static void __call(_Fn __f, _A0& __a0, _A1& __a1)
1044308143Sdim    {
1045308143Sdim        __invoke(__f, __a0, __a1);
1046308143Sdim    }
1047308143Sdim
1048308143Sdim    template <class _Fn, class _A0, class _A1, class _A2>
1049308143Sdim    static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2)
1050308143Sdim    {
1051308143Sdim        __invoke(__f, __a0, __a1, __a2);
1052308143Sdim    }
1053308143Sdim};
1054308143Sdim
1055227825Stheraventemplate <class _Tp>
1056262801Sdimclass _LIBCPP_TYPE_VIS_ONLY reference_wrapper
1057227825Stheraven    : public __weak_result_type<_Tp>
1058227825Stheraven{
1059227825Stheravenpublic:
1060227825Stheraven    // types
1061227825Stheraven    typedef _Tp type;
1062227825Stheravenprivate:
1063227825Stheraven    type* __f_;
1064227825Stheraven
1065227825Stheravenpublic:
1066227825Stheraven    // construct/copy/destroy
1067227825Stheraven    _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) : __f_(&__f) {}
1068227825Stheraven
1069227825Stheraven    // access
1070227825Stheraven    _LIBCPP_INLINE_VISIBILITY operator type&    () const {return *__f_;}
1071227825Stheraven    _LIBCPP_INLINE_VISIBILITY          type& get() const {return *__f_;}
1072227825Stheraven
1073227825Stheraven    // invoke
1074227825Stheraven
1075227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1076227825Stheraven    typename __invoke_return<type&>::type
1077227825Stheraven       operator() () const
1078227825Stheraven       {
1079227825Stheraven           return __invoke(get());
1080227825Stheraven       }
1081227825Stheraven
1082227825Stheraven    template <class _A0>
1083227825Stheraven       _LIBCPP_INLINE_VISIBILITY
1084227825Stheraven       typename __invoke_return0<type&, _A0>::type
1085227825Stheraven          operator() (_A0& __a0) const
1086227825Stheraven          {
1087278724Sdim              return __invoke<type&, _A0>(get(), __a0);
1088227825Stheraven          }
1089227825Stheraven
1090227825Stheraven    template <class _A0, class _A1>
1091227825Stheraven       _LIBCPP_INLINE_VISIBILITY
1092227825Stheraven       typename __invoke_return1<type&, _A0, _A1>::type
1093227825Stheraven          operator() (_A0& __a0, _A1& __a1) const
1094227825Stheraven          {
1095278724Sdim              return __invoke<type&, _A0, _A1>(get(), __a0, __a1);
1096227825Stheraven          }
1097227825Stheraven
1098227825Stheraven    template <class _A0, class _A1, class _A2>
1099227825Stheraven       _LIBCPP_INLINE_VISIBILITY
1100227825Stheraven       typename __invoke_return2<type&, _A0, _A1, _A2>::type
1101227825Stheraven          operator() (_A0& __a0, _A1& __a1, _A2& __a2) const
1102227825Stheraven          {
1103278724Sdim              return __invoke<type&, _A0, _A1, _A2>(get(), __a0, __a1, __a2);
1104227825Stheraven          }
1105227825Stheraven};
1106227825Stheraven
1107278724Sdimtemplate <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
1108278724Sdimtemplate <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
1109227825Stheraventemplate <class _Tp> struct __is_reference_wrapper
1110278724Sdim    : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
1111227825Stheraven
1112227825Stheraventemplate <class _Tp>
1113227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1114227825Stheravenreference_wrapper<_Tp>
1115227825Stheravenref(_Tp& __t)
1116227825Stheraven{
1117227825Stheraven    return reference_wrapper<_Tp>(__t);
1118227825Stheraven}
1119227825Stheraven
1120227825Stheraventemplate <class _Tp>
1121227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1122227825Stheravenreference_wrapper<_Tp>
1123227825Stheravenref(reference_wrapper<_Tp> __t)
1124227825Stheraven{
1125227825Stheraven    return ref(__t.get());
1126227825Stheraven}
1127227825Stheraven
1128227825Stheraventemplate <class _Tp>
1129227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1130227825Stheravenreference_wrapper<const _Tp>
1131227825Stheravencref(const _Tp& __t)
1132227825Stheraven{
1133227825Stheraven    return reference_wrapper<const _Tp>(__t);
1134227825Stheraven}
1135227825Stheraven
1136227825Stheraventemplate <class _Tp>
1137227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1138227825Stheravenreference_wrapper<const _Tp>
1139227825Stheravencref(reference_wrapper<_Tp> __t)
1140227825Stheraven{
1141227825Stheraven    return cref(__t.get());
1142227825Stheraven}
1143227825Stheraven
1144227825Stheraven#endif  // _LIBCPP_FUNCTIONAL_BASE_03
1145