2 //===----------------------------------------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_FUNCTIONAL_BASE_03
12 #define _LIBCPP_FUNCTIONAL_BASE_03
14 // manual variadic expansion for <functional>
19 struct __derives_from_unary_function
22 struct __two {char __lx; char __lxx;};
23 static __two __test(...);
24 template <class _Ap, class _Rp>
25 static unary_function<_Ap, _Rp>
26 __test(const volatile unary_function<_Ap, _Rp>*);
28 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
29 typedef decltype(__test((_Tp*)0)) type;
33 struct __derives_from_binary_function
36 struct __two {char __lx; char __lxx;};
37 static __two __test(...);
38 template <class _A1, class _A2, class _Rp>
39 static binary_function<_A1, _A2, _Rp>
40 __test(const volatile binary_function<_A1, _A2, _Rp>*);
42 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
43 typedef decltype(__test((_Tp*)0)) type;
46 template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
47 struct __maybe_derive_from_unary_function // bool is true
48 : public __derives_from_unary_function<_Tp>::type
53 struct __maybe_derive_from_unary_function<_Tp, false>
57 template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
58 struct __maybe_derive_from_binary_function // bool is true
59 : public __derives_from_binary_function<_Tp>::type
64 struct __maybe_derive_from_binary_function<_Tp, false>
68 template <class _Tp, bool = __has_result_type<_Tp>::value>
69 struct __weak_result_type_imp // bool is true
70 : public __maybe_derive_from_unary_function<_Tp>,
71 public __maybe_derive_from_binary_function<_Tp>
73 typedef typename _Tp::result_type result_type;
77 struct __weak_result_type_imp<_Tp, false>
78 : public __maybe_derive_from_unary_function<_Tp>,
79 public __maybe_derive_from_binary_function<_Tp>
84 struct __weak_result_type
85 : public __weak_result_type_imp<typename remove_reference<_Tp>::type>
92 struct __weak_result_type<_Rp ()>
94 typedef _Rp result_type;
98 struct __weak_result_type<_Rp (&)()>
100 typedef _Rp result_type;
104 struct __weak_result_type<_Rp (*)()>
106 typedef _Rp result_type;
111 template <class _Rp, class _A1>
112 struct __weak_result_type<_Rp (_A1)>
113 : public unary_function<_A1, _Rp>
117 template <class _Rp, class _A1>
118 struct __weak_result_type<_Rp (&)(_A1)>
119 : public unary_function<_A1, _Rp>
123 template <class _Rp, class _A1>
124 struct __weak_result_type<_Rp (*)(_A1)>
125 : public unary_function<_A1, _Rp>
129 template <class _Rp, class _Cp>
130 struct __weak_result_type<_Rp (_Cp::*)()>
131 : public unary_function<_Cp*, _Rp>
135 template <class _Rp, class _Cp>
136 struct __weak_result_type<_Rp (_Cp::*)() const>
137 : public unary_function<const _Cp*, _Rp>
141 template <class _Rp, class _Cp>
142 struct __weak_result_type<_Rp (_Cp::*)() volatile>
143 : public unary_function<volatile _Cp*, _Rp>
147 template <class _Rp, class _Cp>
148 struct __weak_result_type<_Rp (_Cp::*)() const volatile>
149 : public unary_function<const volatile _Cp*, _Rp>
155 template <class _Rp, class _A1, class _A2>
156 struct __weak_result_type<_Rp (_A1, _A2)>
157 : public binary_function<_A1, _A2, _Rp>
161 template <class _Rp, class _A1, class _A2>
162 struct __weak_result_type<_Rp (*)(_A1, _A2)>
163 : public binary_function<_A1, _A2, _Rp>
167 template <class _Rp, class _A1, class _A2>
168 struct __weak_result_type<_Rp (&)(_A1, _A2)>
169 : public binary_function<_A1, _A2, _Rp>
173 template <class _Rp, class _Cp, class _A1>
174 struct __weak_result_type<_Rp (_Cp::*)(_A1)>
175 : public binary_function<_Cp*, _A1, _Rp>
179 template <class _Rp, class _Cp, class _A1>
180 struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
181 : public binary_function<const _Cp*, _A1, _Rp>
185 template <class _Rp, class _Cp, class _A1>
186 struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
187 : public binary_function<volatile _Cp*, _A1, _Rp>
191 template <class _Rp, class _Cp, class _A1>
192 struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
193 : public binary_function<const volatile _Cp*, _A1, _Rp>
197 // 3 or more arguments
199 template <class _Rp, class _A1, class _A2, class _A3>
200 struct __weak_result_type<_Rp (_A1, _A2, _A3)>
202 typedef _Rp result_type;
205 template <class _Rp, class _A1, class _A2, class _A3>
206 struct __weak_result_type<_Rp (&)(_A1, _A2, _A3)>
208 typedef _Rp result_type;
211 template <class _Rp, class _A1, class _A2, class _A3>
212 struct __weak_result_type<_Rp (*)(_A1, _A2, _A3)>
214 typedef _Rp result_type;
217 template <class _Rp, class _Cp, class _A1, class _A2>
218 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2)>
220 typedef _Rp result_type;
223 template <class _Rp, class _Cp, class _A1, class _A2>
224 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) const>
226 typedef _Rp result_type;
229 template <class _Rp, class _Cp, class _A1, class _A2>
230 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) volatile>
232 typedef _Rp result_type;
239 // template <class _Tp, bool _HasResultType>
240 // struct ________ref_return0 // _HasResultType is true
242 // typedef typename _Tp::result_type type;
245 // template <class _Tp>
246 // struct ________ref_return0<_Tp, false>
248 // typedef void type;
251 // template <class _Tp, bool _IsClass>
252 // struct ____ref_return0 // _IsClass is true
253 // : public ________ref_return0<_Tp, __has_result_type<typename remove_cv<_Tp>::type>::value>
257 // template <class _Tp, bool _HasResultType>
258 // struct ______ref_return0 // _HasResultType is true
260 // typedef typename __callable_type<_Tp>::result_type type;
263 // template <class _Tp>
264 // struct ______ref_return0<_Tp, false> // pointer to member data
266 // typedef void type;
269 // template <class _Tp>
270 // struct ____ref_return0<_Tp, false>
271 // : public ______ref_return0<typename remove_cv<_Tp>::type,
272 // __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value>
276 // template <class _Tp>
277 // struct __ref_return0
278 // : public ____ref_return0<typename remove_reference<_Tp>::type,
279 // is_class<typename remove_reference<_Tp>::type>::value>
285 // template <class _Tp, bool _IsClass, class _A0>
286 // struct ____ref_return1 // _IsClass is true
288 // typedef typename result_of<_Tp(_A0)>::type type;
291 // template <class _Tp, bool _HasResultType, class _A0>
292 // struct ______ref_return1 // _HasResultType is true
294 // typedef typename __callable_type<_Tp>::result_type type;
297 // template <class _Tp, class _A0, bool>
298 // struct __ref_return1_member_data1;
300 // template <class _Rp, class _Cp, class _A0>
301 // struct __ref_return1_member_data1<_Rp _Cp::*, _A0, true>
303 // typedef typename __apply_cv<_A0, _Rp>::type& type;
306 // template <class _Rp, class _Cp, class _A0>
307 // struct __ref_return1_member_data1<_Rp _Cp::*, _A0, false>
310 // typedef typename __apply_cv<decltype(*__a), _Rp>::type& type;
313 // template <class _Tp, class _A0>
314 // struct __ref_return1_member_data;
316 // template <class _Rp, class _Cp, class _A0>
317 // struct __ref_return1_member_data<_Rp _Cp::*, _A0>
318 // : public __ref_return1_member_data1<_Rp _Cp::*, _A0,
319 // is_same<typename remove_cv<_Cp>::type,
320 // typename remove_cv<typename remove_reference<_A0>::type>::type>::value>
324 // template <class _Tp, class _A0>
325 // struct ______ref_return1<_Tp, false, _A0> // pointer to member data
326 // : public __ref_return1_member_data<typename remove_cv<_Tp>::type, _A0>
330 // template <class _Tp, class _A0>
331 // struct ____ref_return1<_Tp, false, _A0>
332 // : public ______ref_return1<typename remove_cv<_Tp>::type,
333 // __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0>
337 // template <class _Tp, class _A0>
338 // struct __ref_return1
339 // : public ____ref_return1<typename remove_reference<_Tp>::type,
340 // is_class<typename remove_reference<_Tp>::type>::value, _A0>
346 // template <class _Tp, bool _IsClass, class _A0, class _A1>
347 // struct ____ref_return2 // _IsClass is true
349 // typedef typename result_of<_Tp(_A0, _A1)>::type type;
352 // template <class _Tp, bool _HasResultType, class _A0, class _A1>
353 // struct ______ref_return2 // _HasResultType is true
355 // typedef typename __callable_type<_Tp>::result_type type;
358 // template <class _Tp>
359 // struct ______ref_return2<_Tp, false, class _A0, class _A1> // pointer to member data
361 // static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer"
362 // " to member data with too many arguments.");
365 // template <class _Tp, class _A0, class _A1>
366 // struct ____ref_return2<_Tp, false, _A0, _A1>
367 // : public ______ref_return2<typename remove_cv<_Tp>::type,
368 // __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0, _A1>
372 // template <class _Tp, class _A0, class _A1>
373 // struct __ref_return2
374 // : public ____ref_return2<typename remove_reference<_Tp>::type,
375 // is_class<typename remove_reference<_Tp>::type>::value, _A0, _A1>
381 // template <class _Tp, bool _IsClass, class _A0, class _A1, class _A2>
382 // struct ____ref_return3 // _IsClass is true
384 // typedef typename result_of<_Tp(_A0, _A1, _A2)>::type type;
387 // template <class _Tp, bool _HasResultType, class _A0, class _A1, class _A2>
388 // struct ______ref_return3 // _HasResultType is true
390 // typedef typename __callable_type<_Tp>::result_type type;
393 // template <class _Tp>
394 // struct ______ref_return3<_Tp, false, class _A0, class _A1, class _A2> // pointer to member data
396 // static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer"
397 // " to member data with too many arguments.");
400 // template <class _Tp, class _A0, class _A1, class _A2>
401 // struct ____ref_return3<_Tp, false, _A0, _A1, _A2>
402 // : public ______ref_return3<typename remove_cv<_Tp>::type,
403 // __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0, _A1, _A2>
407 // template <class _Tp, class _A0, class _A1, class _A2>
408 // struct __ref_return3
409 // : public ____ref_return3<typename remove_reference<_Tp>::type,
410 // is_class<typename remove_reference<_Tp>::type>::value, _A0, _A1, _A2>
416 template <class _Rp, class _Tp, class _T1>
417 inline _LIBCPP_INLINE_VISIBILITY
420 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
423 __invoke(_Rp (_Tp::*__f)(), _T1& __t1)
425 return (__t1.*__f)();
428 template <class _Rp, class _Tp, class _T1, class _A0>
429 inline _LIBCPP_INLINE_VISIBILITY
432 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
435 __invoke(_Rp (_Tp::*__f)(_A0), _T1& __t1, _A0& __a0)
437 return (__t1.*__f)(__a0);
440 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
441 inline _LIBCPP_INLINE_VISIBILITY
444 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
447 __invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1& __t1, _A0& __a0, _A1& __a1)
449 return (__t1.*__f)(__a0, __a1);
452 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
453 inline _LIBCPP_INLINE_VISIBILITY
456 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
459 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
461 return (__t1.*__f)(__a0, __a1, __a2);
464 template <class _Rp, class _Tp, class _T1>
465 inline _LIBCPP_INLINE_VISIBILITY
468 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
471 __invoke(_Rp (_Tp::*__f)() const, _T1& __t1)
473 return (__t1.*__f)();
476 template <class _Rp, class _Tp, class _T1, class _A0>
477 inline _LIBCPP_INLINE_VISIBILITY
480 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
483 __invoke(_Rp (_Tp::*__f)(_A0) const, _T1& __t1, _A0& __a0)
485 return (__t1.*__f)(__a0);
488 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
489 inline _LIBCPP_INLINE_VISIBILITY
492 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
495 __invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1& __t1, _A0& __a0, _A1& __a1)
497 return (__t1.*__f)(__a0, __a1);
500 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
501 inline _LIBCPP_INLINE_VISIBILITY
504 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
507 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
509 return (__t1.*__f)(__a0, __a1, __a2);
512 template <class _Rp, class _Tp, class _T1>
513 inline _LIBCPP_INLINE_VISIBILITY
516 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
519 __invoke(_Rp (_Tp::*__f)() volatile, _T1& __t1)
521 return (__t1.*__f)();
524 template <class _Rp, class _Tp, class _T1, class _A0>
525 inline _LIBCPP_INLINE_VISIBILITY
528 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
531 __invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1& __t1, _A0& __a0)
533 return (__t1.*__f)(__a0);
536 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
537 inline _LIBCPP_INLINE_VISIBILITY
540 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
543 __invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1& __t1, _A0& __a0, _A1& __a1)
545 return (__t1.*__f)(__a0, __a1);
548 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
549 inline _LIBCPP_INLINE_VISIBILITY
552 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
555 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
557 return (__t1.*__f)(__a0, __a1, __a2);
560 template <class _Rp, class _Tp, class _T1>
561 inline _LIBCPP_INLINE_VISIBILITY
564 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
567 __invoke(_Rp (_Tp::*__f)() const volatile, _T1& __t1)
569 return (__t1.*__f)();
572 template <class _Rp, class _Tp, class _T1, class _A0>
573 inline _LIBCPP_INLINE_VISIBILITY
576 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
579 __invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1& __t1, _A0& __a0)
581 return (__t1.*__f)(__a0);
584 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
585 inline _LIBCPP_INLINE_VISIBILITY
588 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
591 __invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1& __t1, _A0& __a0, _A1& __a1)
593 return (__t1.*__f)(__a0, __a1);
596 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
597 inline _LIBCPP_INLINE_VISIBILITY
600 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
603 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
605 return (__t1.*__f)(__a0, __a1, __a2);
610 template <class _Rp, class _Tp, class _T1>
611 inline _LIBCPP_INLINE_VISIBILITY
614 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
617 __invoke(_Rp (_Tp::*__f)(), _T1 __t1)
619 return ((*__t1).*__f)();
622 template <class _Rp, class _Tp, class _T1, class _A0>
623 inline _LIBCPP_INLINE_VISIBILITY
626 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
629 __invoke(_Rp (_Tp::*__f)(_A0), _T1 __t1, _A0& __a0)
631 return ((*__t1).*__f)(__a0);
634 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
635 inline _LIBCPP_INLINE_VISIBILITY
638 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
641 __invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1 __t1, _A0& __a0, _A1& __a1)
643 return ((*__t1).*__f)(__a0, __a1);
646 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
647 inline _LIBCPP_INLINE_VISIBILITY
650 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
653 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
655 return ((*__t1).*__f)(__a0, __a1, __a2);
658 template <class _Rp, class _Tp, class _T1>
659 inline _LIBCPP_INLINE_VISIBILITY
662 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
665 __invoke(_Rp (_Tp::*__f)() const, _T1 __t1)
667 return ((*__t1).*__f)();
670 template <class _Rp, class _Tp, class _T1, class _A0>
671 inline _LIBCPP_INLINE_VISIBILITY
674 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
677 __invoke(_Rp (_Tp::*__f)(_A0) const, _T1 __t1, _A0& __a0)
679 return ((*__t1).*__f)(__a0);
682 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
683 inline _LIBCPP_INLINE_VISIBILITY
686 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
689 __invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1 __t1, _A0& __a0, _A1& __a1)
691 return ((*__t1).*__f)(__a0, __a1);
694 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
695 inline _LIBCPP_INLINE_VISIBILITY
698 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
701 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
703 return ((*__t1).*__f)(__a0, __a1, __a2);
706 template <class _Rp, class _Tp, class _T1>
707 inline _LIBCPP_INLINE_VISIBILITY
710 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
713 __invoke(_Rp (_Tp::*__f)() volatile, _T1 __t1)
715 return ((*__t1).*__f)();
718 template <class _Rp, class _Tp, class _T1, class _A0>
719 inline _LIBCPP_INLINE_VISIBILITY
722 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
725 __invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1 __t1, _A0& __a0)
727 return ((*__t1).*__f)(__a0);
730 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
731 inline _LIBCPP_INLINE_VISIBILITY
734 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
737 __invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1 __t1, _A0& __a0, _A1& __a1)
739 return ((*__t1).*__f)(__a0, __a1);
742 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
743 inline _LIBCPP_INLINE_VISIBILITY
746 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
749 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
751 return ((*__t1).*__f)(__a0, __a1, __a2);
754 template <class _Rp, class _Tp, class _T1>
755 inline _LIBCPP_INLINE_VISIBILITY
758 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
761 __invoke(_Rp (_Tp::*__f)() const volatile, _T1 __t1)
763 return ((*__t1).*__f)();
766 template <class _Rp, class _Tp, class _T1, class _A0>
767 inline _LIBCPP_INLINE_VISIBILITY
770 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
773 __invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1 __t1, _A0& __a0)
775 return ((*__t1).*__f)(__a0);
778 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
779 inline _LIBCPP_INLINE_VISIBILITY
782 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
785 __invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1 __t1, _A0& __a0, _A1& __a1)
787 return ((*__t1).*__f)(__a0, __a1);
790 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
791 inline _LIBCPP_INLINE_VISIBILITY
794 !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
797 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
799 return ((*__t1).*__f)(__a0, __a1, __a2);
804 template <class _Rp, class _Tp, class _T1>
805 inline _LIBCPP_INLINE_VISIBILITY
808 is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
809 typename __apply_cv<_T1, _Rp>::type&
811 __invoke(_Rp _Tp::* __f, _T1& __t1)
816 template <class _Rp, class _Tp>
817 inline _LIBCPP_INLINE_VISIBILITY
823 // template <class _Dp, class _Rp, class _Tp, class _T1>
824 // inline _LIBCPP_INLINE_VISIBILITY
825 // typename enable_if
827 // is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
828 // typename __ref_return1<_Rp _Tp::*, _T1>::type
830 // __invoke(_Rp _Tp::* __f, _T1& __t1)
837 template <class _T1, class _Rp, bool>
842 template <class _T1, class _Rp>
843 struct __4th_helper<_T1, _Rp, true>
845 typedef typename __apply_cv<decltype(*_VSTD::declval<_T1>()), _Rp>::type type;
848 template <class _Rp, class _Tp, class _T1>
849 inline _LIBCPP_INLINE_VISIBILITY
850 typename __4th_helper<_T1, _Rp,
852 typename remove_reference<_T1>::type
855 __invoke(_Rp _Tp::* __f, _T1& __t1)
860 // template <class _Dp, class _Rp, class _Tp, class _T1>
861 // inline _LIBCPP_INLINE_VISIBILITY
862 // typename enable_if
864 // !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
865 // typename __ref_return1<_Rp _Tp::*, _T1>::type
867 // __invoke(_Rp _Tp::* __f, _T1 __t1)
869 // return (*__t1).*__f;
875 inline _LIBCPP_INLINE_VISIBILITY
876 decltype(declval<_Fp>()())
882 template <class _Fp, class _A0>
883 inline _LIBCPP_INLINE_VISIBILITY
884 decltype(declval<_Fp>()(declval<_A0&>()))
885 __invoke(_Fp __f, _A0& __a0)
890 template <class _Fp, class _A0, class _A1>
891 inline _LIBCPP_INLINE_VISIBILITY
892 decltype(declval<_Fp>()(declval<_A0&>(), declval<_A1&>()))
893 __invoke(_Fp __f, _A0& __a0, _A1& __a1)
895 return __f(__a0, __a1);
898 template <class _Fp, class _A0, class _A1, class _A2>
899 inline _LIBCPP_INLINE_VISIBILITY
900 decltype(declval<_Fp>()(declval<_A0&>(), declval<_A1&>(), declval<_A2&>()))
901 __invoke(_Fp __f, _A0& __a0, _A1& __a1, _A2& __a2)
903 return __f(__a0, __a1, __a2);
906 // template <class _Rp, class _Fp>
907 // inline _LIBCPP_INLINE_VISIBILITY
909 // __invoke(_Fp& __f)
914 // template <class _Rp, class _Fp, class _A0>
915 // inline _LIBCPP_INLINE_VISIBILITY
916 // typename enable_if
918 // !is_member_pointer<_Fp>::value,
921 // __invoke(_Fp& __f, _A0& __a0)
926 // template <class _Rp, class _Fp, class _A0, class _A1>
927 // inline _LIBCPP_INLINE_VISIBILITY
929 // __invoke(_Fp& __f, _A0& __a0, _A1& __a1)
931 // return __f(__a0, __a1);
934 // template <class _Rp, class _Fp, class _A0, class _A1, class _A2>
935 // inline _LIBCPP_INLINE_VISIBILITY
937 // __invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2)
939 // return __f(__a0, __a1, __a2);
946 struct __two {char __lx; char __lxx;};
947 template <class _Up> static __two __test(...);
948 template <class _Up> static char __test(typename _Up::type* = 0);
950 static const bool value = sizeof(__test<_Tp>(0)) == 1;
953 template <class _Fp, bool = __has_result_type<__weak_result_type<_Fp> >::value>
954 struct __invoke_return
956 typedef typename __weak_result_type<_Fp>::result_type type;
960 struct __invoke_return<_Fp, false>
962 typedef decltype(__invoke(_VSTD::declval<_Fp>())) type;
965 template <class _Tp, class _A0>
966 struct __invoke_return0
968 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>())) type;
971 template <class _Rp, class _Tp, class _A0>
972 struct __invoke_return0<_Rp _Tp::*, _A0>
974 typedef typename __apply_cv<_A0, _Rp>::type& type;
977 template <class _Rp, class _Tp, class _A0>
978 struct __invoke_return0<_Rp _Tp::*, _A0*>
980 typedef typename __apply_cv<_A0, _Rp>::type& type;
983 template <class _Tp, class _A0, class _A1>
984 struct __invoke_return1
986 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(),
987 _VSTD::declval<_A1>())) type;
990 template <class _Tp, class _A0, class _A1, class _A2>
991 struct __invoke_return2
993 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(),
994 _VSTD::declval<_A1>(),
995 _VSTD::declval<_A2>())) type;
999 class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
1000 : public __weak_result_type<_Tp>
1009 // construct/copy/destroy
1010 _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) : __f_(&__f) {}
1013 _LIBCPP_INLINE_VISIBILITY operator type& () const {return *__f_;}
1014 _LIBCPP_INLINE_VISIBILITY type& get() const {return *__f_;}
1018 _LIBCPP_INLINE_VISIBILITY
1019 typename __invoke_return<type&>::type
1022 return __invoke(get());
1025 template <class _A0>
1026 _LIBCPP_INLINE_VISIBILITY
1027 typename __invoke_return0<type&, _A0>::type
1028 operator() (_A0& __a0) const
1030 return __invoke<type&, _A0>(get(), __a0);
1033 template <class _A0, class _A1>
1034 _LIBCPP_INLINE_VISIBILITY
1035 typename __invoke_return1<type&, _A0, _A1>::type
1036 operator() (_A0& __a0, _A1& __a1) const
1038 return __invoke<type&, _A0, _A1>(get(), __a0, __a1);
1041 template <class _A0, class _A1, class _A2>
1042 _LIBCPP_INLINE_VISIBILITY
1043 typename __invoke_return2<type&, _A0, _A1, _A2>::type
1044 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const
1046 return __invoke<type&, _A0, _A1, _A2>(get(), __a0, __a1, __a2);
1050 template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
1051 template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
1052 template <class _Tp> struct __is_reference_wrapper
1053 : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
1055 template <class _Tp>
1056 inline _LIBCPP_INLINE_VISIBILITY
1057 reference_wrapper<_Tp>
1060 return reference_wrapper<_Tp>(__t);
1063 template <class _Tp>
1064 inline _LIBCPP_INLINE_VISIBILITY
1065 reference_wrapper<_Tp>
1066 ref(reference_wrapper<_Tp> __t)
1068 return ref(__t.get());
1071 template <class _Tp>
1072 inline _LIBCPP_INLINE_VISIBILITY
1073 reference_wrapper<const _Tp>
1074 cref(const _Tp& __t)
1076 return reference_wrapper<const _Tp>(__t);
1079 template <class _Tp>
1080 inline _LIBCPP_INLINE_VISIBILITY
1081 reference_wrapper<const _Tp>
1082 cref(reference_wrapper<_Tp> __t)
1084 return cref(__t.get());
1087 #endif // _LIBCPP_FUNCTIONAL_BASE_03