Home | History | Annotate | Download | only in include
      1 // -*- C++ -*-
      2 //===----------------------------------------------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 #ifndef _LIBCPP_FUNCTIONAL_BASE_03
     12 #define _LIBCPP_FUNCTIONAL_BASE_03
     13 
     14 // manual variadic expansion for <functional>
     15 
     16 // __weak_result_type
     17 
     18 template <class _Tp>
     19 struct __derives_from_unary_function
     20 {
     21 private:
     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>*);
     27 public:
     28     static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
     29     typedef decltype(__test((_Tp*)0)) type;
     30 };
     31 
     32 template <class _Tp>
     33 struct __derives_from_binary_function
     34 {
     35 private:
     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>*);
     41 public:
     42     static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
     43     typedef decltype(__test((_Tp*)0)) type;
     44 };
     45 
     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
     49 {
     50 };
     51 
     52 template <class _Tp>
     53 struct __maybe_derive_from_unary_function<_Tp, false>
     54 {
     55 };
     56 
     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
     60 {
     61 };
     62 
     63 template <class _Tp>
     64 struct __maybe_derive_from_binary_function<_Tp, false>
     65 {
     66 };
     67 
     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>
     72 {
     73     typedef typename _Tp::result_type result_type;
     74 };
     75 
     76 template <class _Tp>
     77 struct __weak_result_type_imp<_Tp, false>
     78     : public __maybe_derive_from_unary_function<_Tp>,
     79       public __maybe_derive_from_binary_function<_Tp>
     80 {
     81 };
     82 
     83 template <class _Tp>
     84 struct __weak_result_type
     85     : public __weak_result_type_imp<typename remove_reference<_Tp>::type>
     86 {
     87 };
     88 
     89 // 0 argument case
     90 
     91 template <class _Rp>
     92 struct __weak_result_type<_Rp ()>
     93 {
     94     typedef _Rp result_type;
     95 };
     96 
     97 template <class _Rp>
     98 struct __weak_result_type<_Rp (&)()>
     99 {
    100     typedef _Rp result_type;
    101 };
    102 
    103 template <class _Rp>
    104 struct __weak_result_type<_Rp (*)()>
    105 {
    106     typedef _Rp result_type;
    107 };
    108 
    109 // 1 argument case
    110 
    111 template <class _Rp, class _A1>
    112 struct __weak_result_type<_Rp (_A1)>
    113     : public unary_function<_A1, _Rp>
    114 {
    115 };
    116 
    117 template <class _Rp, class _A1>
    118 struct __weak_result_type<_Rp (&)(_A1)>
    119     : public unary_function<_A1, _Rp>
    120 {
    121 };
    122 
    123 template <class _Rp, class _A1>
    124 struct __weak_result_type<_Rp (*)(_A1)>
    125     : public unary_function<_A1, _Rp>
    126 {
    127 };
    128 
    129 template <class _Rp, class _Cp>
    130 struct __weak_result_type<_Rp (_Cp::*)()>
    131     : public unary_function<_Cp*, _Rp>
    132 {
    133 };
    134 
    135 template <class _Rp, class _Cp>
    136 struct __weak_result_type<_Rp (_Cp::*)() const>
    137     : public unary_function<const _Cp*, _Rp>
    138 {
    139 };
    140 
    141 template <class _Rp, class _Cp>
    142 struct __weak_result_type<_Rp (_Cp::*)() volatile>
    143     : public unary_function<volatile _Cp*, _Rp>
    144 {
    145 };
    146 
    147 template <class _Rp, class _Cp>
    148 struct __weak_result_type<_Rp (_Cp::*)() const volatile>
    149     : public unary_function<const volatile _Cp*, _Rp>
    150 {
    151 };
    152 
    153 // 2 argument case
    154 
    155 template <class _Rp, class _A1, class _A2>
    156 struct __weak_result_type<_Rp (_A1, _A2)>
    157     : public binary_function<_A1, _A2, _Rp>
    158 {
    159 };
    160 
    161 template <class _Rp, class _A1, class _A2>
    162 struct __weak_result_type<_Rp (*)(_A1, _A2)>
    163     : public binary_function<_A1, _A2, _Rp>
    164 {
    165 };
    166 
    167 template <class _Rp, class _A1, class _A2>
    168 struct __weak_result_type<_Rp (&)(_A1, _A2)>
    169     : public binary_function<_A1, _A2, _Rp>
    170 {
    171 };
    172 
    173 template <class _Rp, class _Cp, class _A1>
    174 struct __weak_result_type<_Rp (_Cp::*)(_A1)>
    175     : public binary_function<_Cp*, _A1, _Rp>
    176 {
    177 };
    178 
    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>
    182 {
    183 };
    184 
    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>
    188 {
    189 };
    190 
    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>
    194 {
    195 };
    196 
    197 // 3 or more arguments
    198 
    199 template <class _Rp, class _A1, class _A2, class _A3>
    200 struct __weak_result_type<_Rp (_A1, _A2, _A3)>
    201 {
    202     typedef _Rp result_type;
    203 };
    204 
    205 template <class _Rp, class _A1, class _A2, class _A3>
    206 struct __weak_result_type<_Rp (&)(_A1, _A2, _A3)>
    207 {
    208     typedef _Rp result_type;
    209 };
    210 
    211 template <class _Rp, class _A1, class _A2, class _A3>
    212 struct __weak_result_type<_Rp (*)(_A1, _A2, _A3)>
    213 {
    214     typedef _Rp result_type;
    215 };
    216 
    217 template <class _Rp, class _Cp, class _A1, class _A2>
    218 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2)>
    219 {
    220     typedef _Rp result_type;
    221 };
    222 
    223 template <class _Rp, class _Cp, class _A1, class _A2>
    224 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) const>
    225 {
    226     typedef _Rp result_type;
    227 };
    228 
    229 template <class _Rp, class _Cp, class _A1, class _A2>
    230 struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) volatile>
    231 {
    232     typedef _Rp result_type;
    233 };
    234 
    235 // __invoke
    236 
    237 // __ref_return0
    238 //
    239 // template <class _Tp, bool _HasResultType>
    240 // struct ________ref_return0  // _HasResultType is true
    241 // {
    242 //     typedef typename _Tp::result_type type;
    243 // };
    244 //
    245 // template <class _Tp>
    246 // struct ________ref_return0<_Tp, false>
    247 // {
    248 //     typedef void type;
    249 // };
    250 //
    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>
    254 // {
    255 // };
    256 //
    257 // template <class _Tp, bool _HasResultType>
    258 // struct ______ref_return0  // _HasResultType is true
    259 // {
    260 //     typedef typename __callable_type<_Tp>::result_type type;
    261 // };
    262 //
    263 // template <class _Tp>
    264 // struct ______ref_return0<_Tp, false>  // pointer to member data
    265 // {
    266 //     typedef void type;
    267 // };
    268 //
    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>
    273 // {
    274 // };
    275 //
    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>
    280 // {
    281 // };
    282 //
    283 // __ref_return1
    284 //
    285 // template <class _Tp, bool _IsClass, class _A0>
    286 // struct ____ref_return1  // _IsClass is true
    287 // {
    288 //     typedef typename result_of<_Tp(_A0)>::type type;
    289 // };
    290 //
    291 // template <class _Tp, bool _HasResultType, class _A0>
    292 // struct ______ref_return1  // _HasResultType is true
    293 // {
    294 //     typedef typename __callable_type<_Tp>::result_type type;
    295 // };
    296 //
    297 // template <class _Tp, class _A0, bool>
    298 // struct __ref_return1_member_data1;
    299 //
    300 // template <class _Rp, class _Cp, class _A0>
    301 // struct __ref_return1_member_data1<_Rp _Cp::*, _A0, true>
    302 // {
    303 //     typedef typename __apply_cv<_A0, _Rp>::type& type;
    304 // };
    305 //
    306 // template <class _Rp, class _Cp, class _A0>
    307 // struct __ref_return1_member_data1<_Rp _Cp::*, _A0, false>
    308 // {
    309 //     static _A0 __a;
    310 //     typedef typename __apply_cv<decltype(*__a), _Rp>::type& type;
    311 // };
    312 //
    313 // template <class _Tp, class _A0>
    314 // struct __ref_return1_member_data;
    315 //
    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>
    321 // {
    322 // };
    323 //
    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>
    327 // {
    328 // };
    329 //
    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>
    334 // {
    335 // };
    336 //
    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>
    341 // {
    342 // };
    343 //
    344 // __ref_return2
    345 //
    346 // template <class _Tp, bool _IsClass, class _A0, class _A1>
    347 // struct ____ref_return2  // _IsClass is true
    348 // {
    349 //     typedef typename result_of<_Tp(_A0, _A1)>::type type;
    350 // };
    351 //
    352 // template <class _Tp, bool _HasResultType, class _A0, class _A1>
    353 // struct ______ref_return2  // _HasResultType is true
    354 // {
    355 //     typedef typename __callable_type<_Tp>::result_type type;
    356 // };
    357 //
    358 // template <class _Tp>
    359 // struct ______ref_return2<_Tp, false, class _A0, class _A1>  // pointer to member data
    360 // {
    361 //     static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer"
    362 //                          " to member data with too many arguments.");
    363 // };
    364 //
    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>
    369 // {
    370 // };
    371 //
    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>
    376 // {
    377 // };
    378 //
    379 // __ref_return3
    380 //
    381 // template <class _Tp, bool _IsClass, class _A0, class _A1, class _A2>
    382 // struct ____ref_return3  // _IsClass is true
    383 // {
    384 //     typedef typename result_of<_Tp(_A0, _A1, _A2)>::type type;
    385 // };
    386 //
    387 // template <class _Tp, bool _HasResultType, class _A0, class _A1, class _A2>
    388 // struct ______ref_return3  // _HasResultType is true
    389 // {
    390 //     typedef typename __callable_type<_Tp>::result_type type;
    391 // };
    392 //
    393 // template <class _Tp>
    394 // struct ______ref_return3<_Tp, false, class _A0, class _A1, class _A2>  // pointer to member data
    395 // {
    396 //     static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer"
    397 //                          " to member data with too many arguments.");
    398 // };
    399 //
    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>
    404 // {
    405 // };
    406 //
    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>
    411 // {
    412 // };
    413 
    414 // first bullet
    415 
    416 template <class _Rp, class _Tp, class _T1>
    417 inline _LIBCPP_INLINE_VISIBILITY
    418 typename enable_if
    419 <
    420     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    421     _Rp
    422 >::type
    423 __invoke(_Rp (_Tp::*__f)(), _T1& __t1)
    424 {
    425     return (__t1.*__f)();
    426 }
    427 
    428 template <class _Rp, class _Tp, class _T1, class _A0>
    429 inline _LIBCPP_INLINE_VISIBILITY
    430 typename enable_if
    431 <
    432     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    433     _Rp
    434 >::type
    435 __invoke(_Rp (_Tp::*__f)(_A0), _T1& __t1, _A0& __a0)
    436 {
    437     return (__t1.*__f)(__a0);
    438 }
    439 
    440 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
    441 inline _LIBCPP_INLINE_VISIBILITY
    442 typename enable_if
    443 <
    444     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    445     _Rp
    446 >::type
    447 __invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1& __t1, _A0& __a0, _A1& __a1)
    448 {
    449     return (__t1.*__f)(__a0, __a1);
    450 }
    451 
    452 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
    453 inline _LIBCPP_INLINE_VISIBILITY
    454 typename enable_if
    455 <
    456     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    457     _Rp
    458 >::type
    459 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
    460 {
    461     return (__t1.*__f)(__a0, __a1, __a2);
    462 }
    463 
    464 template <class _Rp, class _Tp, class _T1>
    465 inline _LIBCPP_INLINE_VISIBILITY
    466 typename enable_if
    467 <
    468     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    469     _Rp
    470 >::type
    471 __invoke(_Rp (_Tp::*__f)() const, _T1& __t1)
    472 {
    473     return (__t1.*__f)();
    474 }
    475 
    476 template <class _Rp, class _Tp, class _T1, class _A0>
    477 inline _LIBCPP_INLINE_VISIBILITY
    478 typename enable_if
    479 <
    480     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    481     _Rp
    482 >::type
    483 __invoke(_Rp (_Tp::*__f)(_A0) const, _T1& __t1, _A0& __a0)
    484 {
    485     return (__t1.*__f)(__a0);
    486 }
    487 
    488 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
    489 inline _LIBCPP_INLINE_VISIBILITY
    490 typename enable_if
    491 <
    492     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    493     _Rp
    494 >::type
    495 __invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1& __t1, _A0& __a0, _A1& __a1)
    496 {
    497     return (__t1.*__f)(__a0, __a1);
    498 }
    499 
    500 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
    501 inline _LIBCPP_INLINE_VISIBILITY
    502 typename enable_if
    503 <
    504     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    505     _Rp
    506 >::type
    507 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
    508 {
    509     return (__t1.*__f)(__a0, __a1, __a2);
    510 }
    511 
    512 template <class _Rp, class _Tp, class _T1>
    513 inline _LIBCPP_INLINE_VISIBILITY
    514 typename enable_if
    515 <
    516     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    517     _Rp
    518 >::type
    519 __invoke(_Rp (_Tp::*__f)() volatile, _T1& __t1)
    520 {
    521     return (__t1.*__f)();
    522 }
    523 
    524 template <class _Rp, class _Tp, class _T1, class _A0>
    525 inline _LIBCPP_INLINE_VISIBILITY
    526 typename enable_if
    527 <
    528     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    529     _Rp
    530 >::type
    531 __invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1& __t1, _A0& __a0)
    532 {
    533     return (__t1.*__f)(__a0);
    534 }
    535 
    536 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
    537 inline _LIBCPP_INLINE_VISIBILITY
    538 typename enable_if
    539 <
    540     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    541     _Rp
    542 >::type
    543 __invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1& __t1, _A0& __a0, _A1& __a1)
    544 {
    545     return (__t1.*__f)(__a0, __a1);
    546 }
    547 
    548 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
    549 inline _LIBCPP_INLINE_VISIBILITY
    550 typename enable_if
    551 <
    552     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    553     _Rp
    554 >::type
    555 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
    556 {
    557     return (__t1.*__f)(__a0, __a1, __a2);
    558 }
    559 
    560 template <class _Rp, class _Tp, class _T1>
    561 inline _LIBCPP_INLINE_VISIBILITY
    562 typename enable_if
    563 <
    564     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    565     _Rp
    566 >::type
    567 __invoke(_Rp (_Tp::*__f)() const volatile, _T1& __t1)
    568 {
    569     return (__t1.*__f)();
    570 }
    571 
    572 template <class _Rp, class _Tp, class _T1, class _A0>
    573 inline _LIBCPP_INLINE_VISIBILITY
    574 typename enable_if
    575 <
    576     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    577     _Rp
    578 >::type
    579 __invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1& __t1, _A0& __a0)
    580 {
    581     return (__t1.*__f)(__a0);
    582 }
    583 
    584 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
    585 inline _LIBCPP_INLINE_VISIBILITY
    586 typename enable_if
    587 <
    588     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    589     _Rp
    590 >::type
    591 __invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1& __t1, _A0& __a0, _A1& __a1)
    592 {
    593     return (__t1.*__f)(__a0, __a1);
    594 }
    595 
    596 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
    597 inline _LIBCPP_INLINE_VISIBILITY
    598 typename enable_if
    599 <
    600     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    601     _Rp
    602 >::type
    603 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2)
    604 {
    605     return (__t1.*__f)(__a0, __a1, __a2);
    606 }
    607 
    608 // second bullet
    609 
    610 template <class _Rp, class _Tp, class _T1>
    611 inline _LIBCPP_INLINE_VISIBILITY
    612 typename enable_if
    613 <
    614     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    615     _Rp
    616 >::type
    617 __invoke(_Rp (_Tp::*__f)(), _T1 __t1)
    618 {
    619     return ((*__t1).*__f)();
    620 }
    621 
    622 template <class _Rp, class _Tp, class _T1, class _A0>
    623 inline _LIBCPP_INLINE_VISIBILITY
    624 typename enable_if
    625 <
    626     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    627     _Rp
    628 >::type
    629 __invoke(_Rp (_Tp::*__f)(_A0), _T1 __t1, _A0& __a0)
    630 {
    631     return ((*__t1).*__f)(__a0);
    632 }
    633 
    634 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
    635 inline _LIBCPP_INLINE_VISIBILITY
    636 typename enable_if
    637 <
    638     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    639     _Rp
    640 >::type
    641 __invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1 __t1, _A0& __a0, _A1& __a1)
    642 {
    643     return ((*__t1).*__f)(__a0, __a1);
    644 }
    645 
    646 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
    647 inline _LIBCPP_INLINE_VISIBILITY
    648 typename enable_if
    649 <
    650     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    651     _Rp
    652 >::type
    653 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
    654 {
    655     return ((*__t1).*__f)(__a0, __a1, __a2);
    656 }
    657 
    658 template <class _Rp, class _Tp, class _T1>
    659 inline _LIBCPP_INLINE_VISIBILITY
    660 typename enable_if
    661 <
    662     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    663     _Rp
    664 >::type
    665 __invoke(_Rp (_Tp::*__f)() const, _T1 __t1)
    666 {
    667     return ((*__t1).*__f)();
    668 }
    669 
    670 template <class _Rp, class _Tp, class _T1, class _A0>
    671 inline _LIBCPP_INLINE_VISIBILITY
    672 typename enable_if
    673 <
    674     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    675     _Rp
    676 >::type
    677 __invoke(_Rp (_Tp::*__f)(_A0) const, _T1 __t1, _A0& __a0)
    678 {
    679     return ((*__t1).*__f)(__a0);
    680 }
    681 
    682 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
    683 inline _LIBCPP_INLINE_VISIBILITY
    684 typename enable_if
    685 <
    686     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    687     _Rp
    688 >::type
    689 __invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1 __t1, _A0& __a0, _A1& __a1)
    690 {
    691     return ((*__t1).*__f)(__a0, __a1);
    692 }
    693 
    694 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
    695 inline _LIBCPP_INLINE_VISIBILITY
    696 typename enable_if
    697 <
    698     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    699     _Rp
    700 >::type
    701 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
    702 {
    703     return ((*__t1).*__f)(__a0, __a1, __a2);
    704 }
    705 
    706 template <class _Rp, class _Tp, class _T1>
    707 inline _LIBCPP_INLINE_VISIBILITY
    708 typename enable_if
    709 <
    710     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    711     _Rp
    712 >::type
    713 __invoke(_Rp (_Tp::*__f)() volatile, _T1 __t1)
    714 {
    715     return ((*__t1).*__f)();
    716 }
    717 
    718 template <class _Rp, class _Tp, class _T1, class _A0>
    719 inline _LIBCPP_INLINE_VISIBILITY
    720 typename enable_if
    721 <
    722     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    723     _Rp
    724 >::type
    725 __invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1 __t1, _A0& __a0)
    726 {
    727     return ((*__t1).*__f)(__a0);
    728 }
    729 
    730 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
    731 inline _LIBCPP_INLINE_VISIBILITY
    732 typename enable_if
    733 <
    734     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    735     _Rp
    736 >::type
    737 __invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1 __t1, _A0& __a0, _A1& __a1)
    738 {
    739     return ((*__t1).*__f)(__a0, __a1);
    740 }
    741 
    742 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
    743 inline _LIBCPP_INLINE_VISIBILITY
    744 typename enable_if
    745 <
    746     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    747     _Rp
    748 >::type
    749 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
    750 {
    751     return ((*__t1).*__f)(__a0, __a1, __a2);
    752 }
    753 
    754 template <class _Rp, class _Tp, class _T1>
    755 inline _LIBCPP_INLINE_VISIBILITY
    756 typename enable_if
    757 <
    758     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    759     _Rp
    760 >::type
    761 __invoke(_Rp (_Tp::*__f)() const volatile, _T1 __t1)
    762 {
    763     return ((*__t1).*__f)();
    764 }
    765 
    766 template <class _Rp, class _Tp, class _T1, class _A0>
    767 inline _LIBCPP_INLINE_VISIBILITY
    768 typename enable_if
    769 <
    770     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    771     _Rp
    772 >::type
    773 __invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1 __t1, _A0& __a0)
    774 {
    775     return ((*__t1).*__f)(__a0);
    776 }
    777 
    778 template <class _Rp, class _Tp, class _T1, class _A0, class _A1>
    779 inline _LIBCPP_INLINE_VISIBILITY
    780 typename enable_if
    781 <
    782     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    783     _Rp
    784 >::type
    785 __invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1 __t1, _A0& __a0, _A1& __a1)
    786 {
    787     return ((*__t1).*__f)(__a0, __a1);
    788 }
    789 
    790 template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2>
    791 inline _LIBCPP_INLINE_VISIBILITY
    792 typename enable_if
    793 <
    794     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    795     _Rp
    796 >::type
    797 __invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2)
    798 {
    799     return ((*__t1).*__f)(__a0, __a1, __a2);
    800 }
    801 
    802 // third bullet
    803 
    804 template <class _Rp, class _Tp, class _T1>
    805 inline _LIBCPP_INLINE_VISIBILITY
    806 typename enable_if
    807 <
    808     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    809     typename __apply_cv<_T1, _Rp>::type&
    810 >::type
    811 __invoke(_Rp _Tp::* __f, _T1& __t1)
    812 {
    813     return __t1.*__f;
    814 }
    815 
    816 template <class _Rp, class _Tp>
    817 inline _LIBCPP_INLINE_VISIBILITY
    818 void
    819 __invoke(_Rp _Tp::*)
    820 {
    821 }
    822 
    823 // template <class _Dp, class _Rp, class _Tp, class _T1>
    824 // inline _LIBCPP_INLINE_VISIBILITY
    825 // typename enable_if
    826 // <
    827 //     is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    828 //     typename __ref_return1<_Rp _Tp::*, _T1>::type
    829 // >::type
    830 // __invoke(_Rp _Tp::* __f, _T1& __t1)
    831 // {
    832 //     return __t1.*__f;
    833 // }
    834 
    835 // forth bullet
    836 
    837 template <class _T1, class _Rp, bool>
    838 struct __4th_helper
    839 {
    840 };
    841 
    842 template <class _T1, class _Rp>
    843 struct __4th_helper<_T1, _Rp, true>
    844 {
    845     typedef typename __apply_cv<decltype(*_VSTD::declval<_T1>()), _Rp>::type type;
    846 };
    847 
    848 template <class _Rp, class _Tp, class _T1>
    849 inline _LIBCPP_INLINE_VISIBILITY
    850 typename __4th_helper<_T1, _Rp,
    851                       !is_base_of<_Tp,
    852                                   typename remove_reference<_T1>::type
    853                                  >::value
    854                      >::type&
    855 __invoke(_Rp _Tp::* __f, _T1& __t1)
    856 {
    857     return (*__t1).*__f;
    858 }
    859 
    860 // template <class _Dp, class _Rp, class _Tp, class _T1>
    861 // inline _LIBCPP_INLINE_VISIBILITY
    862 // typename enable_if
    863 // <
    864 //     !is_base_of<_Tp, typename remove_reference<_T1>::type>::value,
    865 //     typename __ref_return1<_Rp _Tp::*, _T1>::type
    866 // >::type
    867 // __invoke(_Rp _Tp::* __f, _T1 __t1)
    868 // {
    869 //     return (*__t1).*__f;
    870 // }
    871 
    872 // fifth bullet
    873 
    874 template <class _Fp>
    875 inline _LIBCPP_INLINE_VISIBILITY
    876 decltype(declval<_Fp>()())
    877 __invoke(_Fp __f)
    878 {
    879     return __f();
    880 }
    881 
    882 template <class _Fp, class _A0>
    883 inline _LIBCPP_INLINE_VISIBILITY
    884 decltype(declval<_Fp>()(declval<_A0&>()))
    885 __invoke(_Fp __f, _A0& __a0)
    886 {
    887     return __f(__a0);
    888 }
    889 
    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)
    894 {
    895     return __f(__a0, __a1);
    896 }
    897 
    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)
    902 {
    903     return __f(__a0, __a1, __a2);
    904 }
    905 
    906 // template <class _Rp, class _Fp>
    907 // inline _LIBCPP_INLINE_VISIBILITY
    908 // _Rp
    909 // __invoke(_Fp& __f)
    910 // {
    911 //     return __f();
    912 // }
    913 //
    914 // template <class _Rp, class _Fp, class _A0>
    915 // inline _LIBCPP_INLINE_VISIBILITY
    916 // typename enable_if
    917 // <
    918 //     !is_member_pointer<_Fp>::value,
    919 //     _Rp
    920 // >::type
    921 // __invoke(_Fp& __f, _A0& __a0)
    922 // {
    923 //     return __f(__a0);
    924 // }
    925 //
    926 // template <class _Rp, class _Fp, class _A0, class _A1>
    927 // inline _LIBCPP_INLINE_VISIBILITY
    928 // _Rp
    929 // __invoke(_Fp& __f, _A0& __a0, _A1& __a1)
    930 // {
    931 //     return __f(__a0, __a1);
    932 // }
    933 //
    934 // template <class _Rp, class _Fp, class _A0, class _A1, class _A2>
    935 // inline _LIBCPP_INLINE_VISIBILITY
    936 // _Rp
    937 // __invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2)
    938 // {
    939 //     return __f(__a0, __a1, __a2);
    940 // }
    941 
    942 template <class _Tp>
    943 struct __has_type
    944 {
    945 private:
    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);
    949 public:
    950     static const bool value = sizeof(__test<_Tp>(0)) == 1;
    951 };
    952 
    953 template <class _Fp, bool = __has_result_type<__weak_result_type<_Fp> >::value>
    954 struct __invoke_return
    955 {
    956     typedef typename __weak_result_type<_Fp>::result_type type;
    957 };
    958 
    959 template <class _Fp>
    960 struct __invoke_return<_Fp, false>
    961 {
    962     typedef decltype(__invoke(_VSTD::declval<_Fp>())) type;
    963 };
    964 
    965 template <class _Tp, class _A0>
    966 struct __invoke_return0
    967 {
    968     typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>())) type;
    969 };
    970 
    971 template <class _Rp, class _Tp, class _A0>
    972 struct __invoke_return0<_Rp _Tp::*, _A0>
    973 {
    974     typedef typename __apply_cv<_A0, _Rp>::type& type;
    975 };
    976 
    977 template <class _Rp, class _Tp, class _A0>
    978 struct __invoke_return0<_Rp _Tp::*, _A0*>
    979 {
    980     typedef typename __apply_cv<_A0, _Rp>::type& type;
    981 };
    982 
    983 template <class _Tp, class _A0, class _A1>
    984 struct __invoke_return1
    985 {
    986     typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(),
    987                                                     _VSTD::declval<_A1>())) type;
    988 };
    989 
    990 template <class _Tp, class _A0, class _A1, class _A2>
    991 struct __invoke_return2
    992 {
    993     typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(),
    994                                                     _VSTD::declval<_A1>(),
    995                                                     _VSTD::declval<_A2>())) type;
    996 };
    997 
    998 template <class _Tp>
    999 class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
   1000     : public __weak_result_type<_Tp>
   1001 {
   1002 public:
   1003     // types
   1004     typedef _Tp type;
   1005 private:
   1006     type* __f_;
   1007 
   1008 public:
   1009     // construct/copy/destroy
   1010     _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) : __f_(&__f) {}
   1011 
   1012     // access
   1013     _LIBCPP_INLINE_VISIBILITY operator type&    () const {return *__f_;}
   1014     _LIBCPP_INLINE_VISIBILITY          type& get() const {return *__f_;}
   1015 
   1016     // invoke
   1017 
   1018     _LIBCPP_INLINE_VISIBILITY
   1019     typename __invoke_return<type&>::type
   1020        operator() () const
   1021        {
   1022            return __invoke(get());
   1023        }
   1024 
   1025     template <class _A0>
   1026        _LIBCPP_INLINE_VISIBILITY
   1027        typename __invoke_return0<type&, _A0>::type
   1028           operator() (_A0& __a0) const
   1029           {
   1030               return __invoke(get(), __a0);
   1031           }
   1032 
   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
   1037           {
   1038               return __invoke(get(), __a0, __a1);
   1039           }
   1040 
   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
   1045           {
   1046               return __invoke(get(), __a0, __a1, __a2);
   1047           }
   1048 };
   1049 
   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> {};
   1054 
   1055 template <class _Tp>
   1056 inline _LIBCPP_INLINE_VISIBILITY
   1057 reference_wrapper<_Tp>
   1058 ref(_Tp& __t)
   1059 {
   1060     return reference_wrapper<_Tp>(__t);
   1061 }
   1062 
   1063 template <class _Tp>
   1064 inline _LIBCPP_INLINE_VISIBILITY
   1065 reference_wrapper<_Tp>
   1066 ref(reference_wrapper<_Tp> __t)
   1067 {
   1068     return ref(__t.get());
   1069 }
   1070 
   1071 template <class _Tp>
   1072 inline _LIBCPP_INLINE_VISIBILITY
   1073 reference_wrapper<const _Tp>
   1074 cref(const _Tp& __t)
   1075 {
   1076     return reference_wrapper<const _Tp>(__t);
   1077 }
   1078 
   1079 template <class _Tp>
   1080 inline _LIBCPP_INLINE_VISIBILITY
   1081 reference_wrapper<const _Tp>
   1082 cref(reference_wrapper<_Tp> __t)
   1083 {
   1084     return cref(__t.get());
   1085 }
   1086 
   1087 #endif  // _LIBCPP_FUNCTIONAL_BASE_03
   1088