00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 namespace std
00036 {
00037 _GLIBCXX_BEGIN_NAMESPACE_TR1
00038
00039 template<typename _MemberPointer>
00040 class _Mem_fn;
00041
00042
00043
00044
00045
00046
00047 template<typename _Tp>
00048 class _Has_result_type_helper : __sfinae_types
00049 {
00050 template<typename _Up>
00051 struct _Wrap_type
00052 { };
00053
00054 template<typename _Up>
00055 static __one __test(_Wrap_type<typename _Up::result_type>*);
00056
00057 template<typename _Up>
00058 static __two __test(...);
00059
00060 public:
00061 static const bool value = sizeof(__test<_Tp>(0)) == 1;
00062 };
00063
00064 template<typename _Tp>
00065 struct _Has_result_type
00066 : integral_constant<bool,
00067 _Has_result_type_helper<typename remove_cv<_Tp>::type>::value>
00068 { };
00069
00070
00071
00072
00073
00074 template<bool _Has_result_type, typename _Functor>
00075 struct _Maybe_get_result_type
00076 { };
00077
00078 template<typename _Functor>
00079 struct _Maybe_get_result_type<true, _Functor>
00080 {
00081 typedef typename _Functor::result_type result_type;
00082 };
00083
00084
00085
00086
00087
00088 template<typename _Functor>
00089 struct _Weak_result_type_impl
00090 : _Maybe_get_result_type<_Has_result_type<_Functor>::value, _Functor>
00091 {
00092 };
00093
00094
00095 template<typename _Res, typename... _ArgTypes>
00096 struct _Weak_result_type_impl<_Res(_ArgTypes...)>
00097 {
00098 typedef _Res result_type;
00099 };
00100
00101
00102 template<typename _Res, typename... _ArgTypes>
00103 struct _Weak_result_type_impl<_Res(&)(_ArgTypes...)>
00104 {
00105 typedef _Res result_type;
00106 };
00107
00108
00109 template<typename _Res, typename... _ArgTypes>
00110 struct _Weak_result_type_impl<_Res(*)(_ArgTypes...)>
00111 {
00112 typedef _Res result_type;
00113 };
00114
00115
00116 template<typename _Res, typename _Class, typename... _ArgTypes>
00117 struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)>
00118 {
00119 typedef _Res result_type;
00120 };
00121
00122
00123 template<typename _Res, typename _Class, typename... _ArgTypes>
00124 struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) const>
00125 {
00126 typedef _Res result_type;
00127 };
00128
00129
00130 template<typename _Res, typename _Class, typename... _ArgTypes>
00131 struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) volatile>
00132 {
00133 typedef _Res result_type;
00134 };
00135
00136
00137 template<typename _Res, typename _Class, typename... _ArgTypes>
00138 struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)const volatile>
00139 {
00140 typedef _Res result_type;
00141 };
00142
00143
00144
00145
00146
00147 template<typename _Functor>
00148 struct _Weak_result_type
00149 : _Weak_result_type_impl<typename remove_cv<_Functor>::type>
00150 {
00151 };
00152
00153 template<typename _Signature>
00154 class result_of;
00155
00156
00157
00158
00159
00160
00161
00162 template<bool _Has_result_type, typename _Signature>
00163 struct _Result_of_impl;
00164
00165
00166 template<typename _Res, typename _Class, typename _T1>
00167 struct _Result_of_impl<false, _Res _Class::*(_T1)>
00168 {
00169 typedef typename _Mem_fn<_Res _Class::*>
00170 ::template _Result_type<_T1>::type type;
00171 };
00172
00173
00174
00175
00176
00177 template<typename _Functor, typename... _ArgTypes>
00178 class result_of<_Functor(_ArgTypes...)>
00179 : public _Result_of_impl<
00180 _Has_result_type<_Weak_result_type<_Functor> >::value,
00181 _Functor(_ArgTypes...)>
00182 {
00183 };
00184
00185
00186 template<typename _Functor, typename... _ArgTypes>
00187 struct _Result_of_impl<true, _Functor(_ArgTypes...)>
00188 {
00189 typedef typename _Weak_result_type<_Functor>::result_type type;
00190 };
00191
00192
00193
00194
00195
00196 template<typename _Functor, typename... _ArgTypes>
00197 struct _Result_of_impl<false, _Functor(_ArgTypes...)>
00198 {
00199 typedef typename _Functor
00200 ::template result<_Functor(_ArgTypes...)>::type type;
00201 };
00202
00203
00204
00205
00206
00207 template<typename _Functor>
00208 struct _Result_of_impl<false, _Functor()>
00209 {
00210 typedef void type;
00211 };
00212
00213
00214 template<typename _Tp>
00215 struct _Derives_from_unary_function : __sfinae_types
00216 {
00217 private:
00218 template<typename _T1, typename _Res>
00219 static __one __test(const volatile unary_function<_T1, _Res>*);
00220
00221
00222
00223 static __two __test(...);
00224
00225 public:
00226 static const bool value = sizeof(__test((_Tp*)0)) == 1;
00227 };
00228
00229
00230 template<typename _Tp>
00231 struct _Derives_from_binary_function : __sfinae_types
00232 {
00233 private:
00234 template<typename _T1, typename _T2, typename _Res>
00235 static __one __test(const volatile binary_function<_T1, _T2, _Res>*);
00236
00237
00238
00239 static __two __test(...);
00240
00241 public:
00242 static const bool value = sizeof(__test((_Tp*)0)) == 1;
00243 };
00244
00245
00246 template<typename _Tp, bool _IsFunctionType = is_function<_Tp>::value>
00247 struct _Function_to_function_pointer
00248 {
00249 typedef _Tp type;
00250 };
00251
00252 template<typename _Tp>
00253 struct _Function_to_function_pointer<_Tp, true>
00254 {
00255 typedef _Tp* type;
00256 };
00257
00258
00259
00260
00261
00262 template<typename _Functor, typename... _Args>
00263 inline
00264 typename __gnu_cxx::__enable_if<
00265 (!is_member_pointer<_Functor>::value
00266 && !is_function<_Functor>::value
00267 && !is_function<typename remove_pointer<_Functor>::type>::value),
00268 typename result_of<_Functor(_Args...)>::type
00269 >::__type
00270 __invoke(_Functor& __f, _Args&... __args)
00271 {
00272 return __f(__args...);
00273 }
00274
00275 template<typename _Functor, typename... _Args>
00276 inline
00277 typename __gnu_cxx::__enable_if<
00278 (is_member_pointer<_Functor>::value
00279 && !is_function<_Functor>::value
00280 && !is_function<typename remove_pointer<_Functor>::type>::value),
00281 typename result_of<_Functor(_Args...)>::type
00282 >::__type
00283 __invoke(_Functor& __f, _Args&... __args)
00284 {
00285 return mem_fn(__f)(__args...);
00286 }
00287
00288
00289 template<typename _Functor, typename... _Args>
00290 inline
00291 typename __gnu_cxx::__enable_if<
00292 (is_pointer<_Functor>::value
00293 && is_function<typename remove_pointer<_Functor>::type>::value),
00294 typename result_of<_Functor(_Args...)>::type
00295 >::__type
00296 __invoke(_Functor __f, _Args&... __args)
00297 {
00298 return __f(__args...);
00299 }
00300
00301
00302
00303
00304
00305
00306 template<bool _Unary, bool _Binary, typename _Tp>
00307 struct _Reference_wrapper_base_impl;
00308
00309
00310 template<typename _Tp>
00311 struct _Reference_wrapper_base_impl<false, false, _Tp>
00312 : _Weak_result_type<_Tp>
00313 { };
00314
00315
00316 template<typename _Tp>
00317 struct _Reference_wrapper_base_impl<true, false, _Tp>
00318 : unary_function<typename _Tp::argument_type,
00319 typename _Tp::result_type>
00320 { };
00321
00322
00323 template<typename _Tp>
00324 struct _Reference_wrapper_base_impl<false, true, _Tp>
00325 : binary_function<typename _Tp::first_argument_type,
00326 typename _Tp::second_argument_type,
00327 typename _Tp::result_type>
00328 { };
00329
00330
00331
00332 template<typename _Tp>
00333 struct _Reference_wrapper_base_impl<true, true, _Tp>
00334 : unary_function<typename _Tp::argument_type,
00335 typename _Tp::result_type>,
00336 binary_function<typename _Tp::first_argument_type,
00337 typename _Tp::second_argument_type,
00338 typename _Tp::result_type>
00339 {
00340 typedef typename _Tp::result_type result_type;
00341 };
00342
00343
00344
00345
00346
00347
00348
00349 template<typename _Tp>
00350 struct _Reference_wrapper_base
00351 : _Reference_wrapper_base_impl<
00352 _Derives_from_unary_function<_Tp>::value,
00353 _Derives_from_binary_function<_Tp>::value,
00354 _Tp>
00355 { };
00356
00357
00358 template<typename _Res, typename _T1>
00359 struct _Reference_wrapper_base<_Res(_T1)>
00360 : unary_function<_T1, _Res>
00361 { };
00362
00363
00364 template<typename _Res, typename _T1, typename _T2>
00365 struct _Reference_wrapper_base<_Res(_T1, _T2)>
00366 : binary_function<_T1, _T2, _Res>
00367 { };
00368
00369
00370 template<typename _Res, typename _T1>
00371 struct _Reference_wrapper_base<_Res(*)(_T1)>
00372 : unary_function<_T1, _Res>
00373 { };
00374
00375
00376 template<typename _Res, typename _T1, typename _T2>
00377 struct _Reference_wrapper_base<_Res(*)(_T1, _T2)>
00378 : binary_function<_T1, _T2, _Res>
00379 { };
00380
00381
00382 template<typename _Res, typename _T1>
00383 struct _Reference_wrapper_base<_Res (_T1::*)()>
00384 : unary_function<_T1*, _Res>
00385 { };
00386
00387
00388 template<typename _Res, typename _T1, typename _T2>
00389 struct _Reference_wrapper_base<_Res (_T1::*)(_T2)>
00390 : binary_function<_T1*, _T2, _Res>
00391 { };
00392
00393
00394 template<typename _Res, typename _T1>
00395 struct _Reference_wrapper_base<_Res (_T1::*)() const>
00396 : unary_function<const _T1*, _Res>
00397 { };
00398
00399
00400 template<typename _Res, typename _T1, typename _T2>
00401 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const>
00402 : binary_function<const _T1*, _T2, _Res>
00403 { };
00404
00405
00406 template<typename _Res, typename _T1>
00407 struct _Reference_wrapper_base<_Res (_T1::*)() volatile>
00408 : unary_function<volatile _T1*, _Res>
00409 { };
00410
00411
00412 template<typename _Res, typename _T1, typename _T2>
00413 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile>
00414 : binary_function<volatile _T1*, _T2, _Res>
00415 { };
00416
00417
00418 template<typename _Res, typename _T1>
00419 struct _Reference_wrapper_base<_Res (_T1::*)() const volatile>
00420 : unary_function<const volatile _T1*, _Res>
00421 { };
00422
00423
00424 template<typename _Res, typename _T1, typename _T2>
00425 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile>
00426 : binary_function<const volatile _T1*, _T2, _Res>
00427 { };
00428
00429
00430 template<typename _Tp>
00431 class reference_wrapper
00432 : public _Reference_wrapper_base<typename remove_cv<_Tp>::type>
00433 {
00434
00435
00436 typedef typename _Function_to_function_pointer<_Tp>::type
00437 _M_func_type;
00438
00439 _Tp* _M_data;
00440 public:
00441 typedef _Tp type;
00442
00443 explicit
00444 reference_wrapper(_Tp& __indata): _M_data(&__indata)
00445 { }
00446
00447 reference_wrapper(const reference_wrapper<_Tp>& __inref):
00448 _M_data(__inref._M_data)
00449 { }
00450
00451 reference_wrapper&
00452 operator=(const reference_wrapper<_Tp>& __inref)
00453 {
00454 _M_data = __inref._M_data;
00455 return *this;
00456 }
00457
00458 operator _Tp&() const
00459 { return this->get(); }
00460
00461 _Tp&
00462 get() const
00463 { return *_M_data; }
00464
00465 template<typename... _Args>
00466 typename result_of<_M_func_type(_Args...)>::type
00467 operator()(_Args&... __args) const
00468 {
00469 return __invoke(get(), __args...);
00470 }
00471 };
00472
00473
00474
00475 template<typename _Tp>
00476 inline reference_wrapper<_Tp>
00477 ref(_Tp& __t)
00478 { return reference_wrapper<_Tp>(__t); }
00479
00480
00481 template<typename _Tp>
00482 inline reference_wrapper<const _Tp>
00483 cref(const _Tp& __t)
00484 { return reference_wrapper<const _Tp>(__t); }
00485
00486 template<typename _Tp>
00487 inline reference_wrapper<_Tp>
00488 ref(reference_wrapper<_Tp> __t)
00489 { return ref(__t.get()); }
00490
00491 template<typename _Tp>
00492 inline reference_wrapper<const _Tp>
00493 cref(reference_wrapper<_Tp> __t)
00494 { return cref(__t.get()); }
00495
00496 template<typename _Tp, bool>
00497 struct _Mem_fn_const_or_non
00498 {
00499 typedef const _Tp& type;
00500 };
00501
00502 template<typename _Tp>
00503 struct _Mem_fn_const_or_non<_Tp, false>
00504 {
00505 typedef _Tp& type;
00506 };
00507
00508
00509
00510
00511
00512
00513 template<typename _Res, typename... _ArgTypes>
00514 struct _Maybe_unary_or_binary_function { };
00515
00516
00517 template<typename _Res, typename _T1>
00518 struct _Maybe_unary_or_binary_function<_Res, _T1>
00519 : std::unary_function<_T1, _Res> { };
00520
00521
00522 template<typename _Res, typename _T1, typename _T2>
00523 struct _Maybe_unary_or_binary_function<_Res, _T1, _T2>
00524 : std::binary_function<_T1, _T2, _Res> { };
00525
00526
00527 template<typename _Res, typename _Class, typename... _ArgTypes>
00528 class _Mem_fn<_Res (_Class::*)(_ArgTypes...)>
00529 : public _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...>
00530 {
00531 typedef _Res (_Class::*_Functor)(_ArgTypes...);
00532
00533 template<typename _Tp>
00534 _Res
00535 _M_call(_Tp& __object, const volatile _Class *,
00536 _ArgTypes... __args) const
00537 { return (__object.*__pmf)(__args...); }
00538
00539 template<typename _Tp>
00540 _Res
00541 _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
00542 { return ((*__ptr).*__pmf)(__args...); }
00543
00544 public:
00545 typedef _Res result_type;
00546
00547 explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
00548
00549
00550 _Res
00551 operator()(_Class& __object, _ArgTypes... __args) const
00552 { return (__object.*__pmf)(__args...); }
00553
00554
00555 _Res
00556 operator()(_Class* __object, _ArgTypes... __args) const
00557 { return (__object->*__pmf)(__args...); }
00558
00559
00560 template<typename _Tp>
00561 _Res
00562 operator()(_Tp& __object, _ArgTypes... __args) const
00563 { return _M_call(__object, &__object, __args...); }
00564
00565 private:
00566 _Functor __pmf;
00567 };
00568
00569
00570 template<typename _Res, typename _Class, typename... _ArgTypes>
00571 class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const>
00572 : public _Maybe_unary_or_binary_function<_Res, const _Class*,
00573 _ArgTypes...>
00574 {
00575 typedef _Res (_Class::*_Functor)(_ArgTypes...) const;
00576
00577 template<typename _Tp>
00578 _Res
00579 _M_call(_Tp& __object, const volatile _Class *,
00580 _ArgTypes... __args) const
00581 { return (__object.*__pmf)(__args...); }
00582
00583 template<typename _Tp>
00584 _Res
00585 _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
00586 { return ((*__ptr).*__pmf)(__args...); }
00587
00588 public:
00589 typedef _Res result_type;
00590
00591 explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
00592
00593
00594 _Res
00595 operator()(const _Class& __object, _ArgTypes... __args) const
00596 { return (__object.*__pmf)(__args...); }
00597
00598
00599 _Res
00600 operator()(const _Class* __object, _ArgTypes... __args) const
00601 { return (__object->*__pmf)(__args...); }
00602
00603
00604 template<typename _Tp>
00605 _Res operator()(_Tp& __object, _ArgTypes... __args) const
00606 { return _M_call(__object, &__object, __args...); }
00607
00608 private:
00609 _Functor __pmf;
00610 };
00611
00612
00613 template<typename _Res, typename _Class, typename... _ArgTypes>
00614 class _Mem_fn<_Res (_Class::*)(_ArgTypes...) volatile>
00615 : public _Maybe_unary_or_binary_function<_Res, volatile _Class*,
00616 _ArgTypes...>
00617 {
00618 typedef _Res (_Class::*_Functor)(_ArgTypes...) volatile;
00619
00620 template<typename _Tp>
00621 _Res
00622 _M_call(_Tp& __object, const volatile _Class *,
00623 _ArgTypes... __args) const
00624 { return (__object.*__pmf)(__args...); }
00625
00626 template<typename _Tp>
00627 _Res
00628 _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
00629 { return ((*__ptr).*__pmf)(__args...); }
00630
00631 public:
00632 typedef _Res result_type;
00633
00634 explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
00635
00636
00637 _Res
00638 operator()(volatile _Class& __object, _ArgTypes... __args) const
00639 { return (__object.*__pmf)(__args...); }
00640
00641
00642 _Res
00643 operator()(volatile _Class* __object, _ArgTypes... __args) const
00644 { return (__object->*__pmf)(__args...); }
00645
00646
00647 template<typename _Tp>
00648 _Res
00649 operator()(_Tp& __object, _ArgTypes... __args) const
00650 { return _M_call(__object, &__object, __args...); }
00651
00652 private:
00653 _Functor __pmf;
00654 };
00655
00656
00657 template<typename _Res, typename _Class, typename... _ArgTypes>
00658 class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const volatile>
00659 : public _Maybe_unary_or_binary_function<_Res, const volatile _Class*,
00660 _ArgTypes...>
00661 {
00662 typedef _Res (_Class::*_Functor)(_ArgTypes...) const volatile;
00663
00664 template<typename _Tp>
00665 _Res
00666 _M_call(_Tp& __object, const volatile _Class *,
00667 _ArgTypes... __args) const
00668 { return (__object.*__pmf)(__args...); }
00669
00670 template<typename _Tp>
00671 _Res
00672 _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
00673 { return ((*__ptr).*__pmf)(__args...); }
00674
00675 public:
00676 typedef _Res result_type;
00677
00678 explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
00679
00680
00681 _Res
00682 operator()(const volatile _Class& __object, _ArgTypes... __args) const
00683 { return (__object.*__pmf)(__args...); }
00684
00685
00686 _Res
00687 operator()(const volatile _Class* __object, _ArgTypes... __args) const
00688 { return (__object->*__pmf)(__args...); }
00689
00690
00691 template<typename _Tp>
00692 _Res operator()(_Tp& __object, _ArgTypes... __args) const
00693 { return _M_call(__object, &__object, __args...); }
00694
00695 private:
00696 _Functor __pmf;
00697 };
00698
00699
00700 template<typename _Res, typename _Class>
00701 class _Mem_fn<_Res _Class::*>
00702 {
00703
00704
00705 template<typename _Tp>
00706 _Res&
00707 _M_call(_Tp& __object, _Class *) const
00708 { return __object.*__pm; }
00709
00710 template<typename _Tp, typename _Up>
00711 _Res&
00712 _M_call(_Tp& __object, _Up * const *) const
00713 { return (*__object).*__pm; }
00714
00715 template<typename _Tp, typename _Up>
00716 const _Res&
00717 _M_call(_Tp& __object, const _Up * const *) const
00718 { return (*__object).*__pm; }
00719
00720 template<typename _Tp>
00721 const _Res&
00722 _M_call(_Tp& __object, const _Class *) const
00723 { return __object.*__pm; }
00724
00725 template<typename _Tp>
00726 const _Res&
00727 _M_call(_Tp& __ptr, const volatile void*) const
00728 { return (*__ptr).*__pm; }
00729
00730 template<typename _Tp> static _Tp& __get_ref();
00731
00732 template<typename _Tp>
00733 static __sfinae_types::__one __check_const(_Tp&, _Class*);
00734 template<typename _Tp, typename _Up>
00735 static __sfinae_types::__one __check_const(_Tp&, _Up * const *);
00736 template<typename _Tp, typename _Up>
00737 static __sfinae_types::__two __check_const(_Tp&, const _Up * const *);
00738 template<typename _Tp>
00739 static __sfinae_types::__two __check_const(_Tp&, const _Class*);
00740 template<typename _Tp>
00741 static __sfinae_types::__two __check_const(_Tp&, const volatile void*);
00742
00743 public:
00744 template<typename _Tp>
00745 struct _Result_type
00746 : _Mem_fn_const_or_non<_Res,
00747 (sizeof(__sfinae_types::__two)
00748 == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))>
00749 { };
00750
00751 template<typename _Signature>
00752 struct result;
00753
00754 template<typename _CVMem, typename _Tp>
00755 struct result<_CVMem(_Tp)>
00756 : public _Result_type<_Tp> { };
00757
00758 template<typename _CVMem, typename _Tp>
00759 struct result<_CVMem(_Tp&)>
00760 : public _Result_type<_Tp> { };
00761
00762 explicit
00763 _Mem_fn(_Res _Class::*__pm) : __pm(__pm) { }
00764
00765
00766 _Res&
00767 operator()(_Class& __object) const
00768 { return __object.*__pm; }
00769
00770 const _Res&
00771 operator()(const _Class& __object) const
00772 { return __object.*__pm; }
00773
00774
00775 _Res&
00776 operator()(_Class* __object) const
00777 { return __object->*__pm; }
00778
00779 const _Res&
00780 operator()(const _Class* __object) const
00781 { return __object->*__pm; }
00782
00783
00784 template<typename _Tp>
00785 typename _Result_type<_Tp>::type
00786 operator()(_Tp& __unknown) const
00787 { return _M_call(__unknown, &__unknown); }
00788
00789 private:
00790 _Res _Class::*__pm;
00791 };
00792
00793
00794
00795
00796
00797 template<typename _Tp, typename _Class>
00798 inline _Mem_fn<_Tp _Class::*>
00799 mem_fn(_Tp _Class::* __pm)
00800 {
00801 return _Mem_fn<_Tp _Class::*>(__pm);
00802 }
00803
00804
00805
00806
00807
00808
00809 template<typename _Tp>
00810 struct is_bind_expression
00811 { static const bool value = false; };
00812
00813 template<typename _Tp>
00814 const bool is_bind_expression<_Tp>::value;
00815
00816
00817
00818
00819
00820 template<typename _Tp>
00821 struct is_placeholder
00822 { static const int value = 0; };
00823
00824 template<typename _Tp>
00825 const int is_placeholder<_Tp>::value;
00826
00827
00828 template<int _Num> struct _Placeholder { };
00829
00830
00831
00832
00833 namespace placeholders
00834 {
00835 namespace
00836 {
00837 _Placeholder<1> _1;
00838 _Placeholder<2> _2;
00839 _Placeholder<3> _3;
00840 _Placeholder<4> _4;
00841 _Placeholder<5> _5;
00842 _Placeholder<6> _6;
00843 _Placeholder<7> _7;
00844 _Placeholder<8> _8;
00845 _Placeholder<9> _9;
00846 _Placeholder<10> _10;
00847 _Placeholder<11> _11;
00848 _Placeholder<12> _12;
00849 _Placeholder<13> _13;
00850 _Placeholder<14> _14;
00851 _Placeholder<15> _15;
00852 _Placeholder<16> _16;
00853 _Placeholder<17> _17;
00854 _Placeholder<18> _18;
00855 _Placeholder<19> _19;
00856 _Placeholder<20> _20;
00857 _Placeholder<21> _21;
00858 _Placeholder<22> _22;
00859 _Placeholder<23> _23;
00860 _Placeholder<24> _24;
00861 _Placeholder<25> _25;
00862 _Placeholder<26> _26;
00863 _Placeholder<27> _27;
00864 _Placeholder<28> _28;
00865 _Placeholder<29> _29;
00866 }
00867 }
00868
00869
00870
00871
00872
00873 template<int _Num>
00874 struct is_placeholder<_Placeholder<_Num> >
00875 { static const int value = _Num; };
00876
00877 template<int _Num>
00878 const int is_placeholder<_Placeholder<_Num> >::value;
00879
00880
00881
00882
00883
00884 template<int... _Indexes>
00885 struct _Index_tuple { };
00886
00887
00888 template<std::size_t _Num, typename _Tuple = _Index_tuple<> >
00889 struct _Build_index_tuple;
00890
00891 template<std::size_t _Num, int... _Indexes>
00892 struct _Build_index_tuple<_Num, _Index_tuple<_Indexes...> >
00893 : _Build_index_tuple<_Num - 1,
00894 _Index_tuple<_Indexes..., sizeof...(_Indexes)> >
00895 {
00896 };
00897
00898 template<int... _Indexes>
00899 struct _Build_index_tuple<0, _Index_tuple<_Indexes...> >
00900 {
00901 typedef _Index_tuple<_Indexes...> __type;
00902 };
00903
00904
00905
00906
00907
00908 struct _No_tuple_element;
00909
00910
00911
00912
00913
00914
00915 template<int __i, typename _Tuple, bool _IsSafe>
00916 struct _Safe_tuple_element_impl
00917 : tuple_element<__i, _Tuple> { };
00918
00919
00920
00921
00922
00923
00924 template<int __i, typename _Tuple>
00925 struct _Safe_tuple_element_impl<__i, _Tuple, false>
00926 {
00927 typedef _No_tuple_element type;
00928 };
00929
00930
00931
00932
00933
00934 template<int __i, typename _Tuple>
00935 struct _Safe_tuple_element
00936 : _Safe_tuple_element_impl<__i, _Tuple,
00937 (__i >= 0 && __i < tuple_size<_Tuple>::value)>
00938 {
00939 };
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952 template<typename _Arg,
00953 bool _IsBindExp = is_bind_expression<_Arg>::value,
00954 bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
00955 class _Mu;
00956
00957
00958
00959
00960
00961 template<typename _Tp>
00962 class _Mu<reference_wrapper<_Tp>, false, false>
00963 {
00964 public:
00965 typedef _Tp& result_type;
00966
00967
00968
00969
00970
00971 template<typename _CVRef, typename _Tuple>
00972 result_type
00973 operator()(_CVRef& __arg, const _Tuple&) const volatile
00974 { return __arg.get(); }
00975 };
00976
00977
00978
00979
00980
00981
00982 template<typename _Arg>
00983 class _Mu<_Arg, true, false>
00984 {
00985 public:
00986 template<typename _Signature> class result;
00987
00988
00989
00990
00991 template<typename _CVMu, typename _CVArg, typename... _Args>
00992 class result<_CVMu(_CVArg, tuple<_Args...>)>
00993 : public result_of<_CVArg(_Args...)> { };
00994
00995 template<typename _CVArg, typename... _Args>
00996 typename result_of<_CVArg(_Args...)>::type
00997 operator()(_CVArg& __arg,
00998 const tuple<_Args...>& __tuple) const volatile
00999 {
01000
01001 typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
01002 _Indexes;
01003 return this->__call(__arg, __tuple, _Indexes());
01004 }
01005
01006 private:
01007
01008
01009 template<typename _CVArg, typename... _Args, int... _Indexes>
01010 typename result_of<_CVArg(_Args...)>::type
01011 __call(_CVArg& __arg, const tuple<_Args...>& __tuple,
01012 const _Index_tuple<_Indexes...>&) const volatile
01013 {
01014 return __arg(_GLIBCXX_TR1 get<_Indexes>(__tuple)...);
01015 }
01016 };
01017
01018
01019
01020
01021
01022
01023 template<typename _Arg>
01024 class _Mu<_Arg, false, true>
01025 {
01026 public:
01027 template<typename _Signature> class result;
01028
01029 template<typename _CVMu, typename _CVArg, typename _Tuple>
01030 class result<_CVMu(_CVArg, _Tuple)>
01031 {
01032
01033
01034
01035 typedef typename _Safe_tuple_element<(is_placeholder<_Arg>::value
01036 - 1), _Tuple>::type
01037 __base_type;
01038
01039 public:
01040 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
01041 typedef typename add_lvalue_reference<__base_type>::type type;
01042 #else
01043 typedef typename add_reference<__base_type>::type type;
01044 #endif
01045 };
01046
01047 template<typename _Tuple>
01048 typename result<_Mu(_Arg, _Tuple)>::type
01049 operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile
01050 {
01051 return ::std::_GLIBCXX_TR1 get<(is_placeholder<_Arg>::value
01052 - 1)>(__tuple);
01053 }
01054 };
01055
01056
01057
01058
01059
01060
01061 template<typename _Arg>
01062 class _Mu<_Arg, false, false>
01063 {
01064 public:
01065 template<typename _Signature> struct result;
01066
01067 template<typename _CVMu, typename _CVArg, typename _Tuple>
01068 struct result<_CVMu(_CVArg, _Tuple)>
01069 {
01070 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
01071 typedef typename add_lvalue_reference<_CVArg>::type type;
01072 #else
01073 typedef typename add_reference<_CVArg>::type type;
01074 #endif
01075 };
01076
01077
01078 template<typename _CVArg, typename _Tuple>
01079 _CVArg&
01080 operator()(_CVArg& __arg, const _Tuple&) const volatile
01081 { return __arg; }
01082 };
01083
01084
01085
01086
01087
01088
01089 template<typename _Tp>
01090 struct _Maybe_wrap_member_pointer
01091 {
01092 typedef _Tp type;
01093
01094 static const _Tp&
01095 __do_wrap(const _Tp& __x)
01096 { return __x; }
01097 };
01098
01099
01100
01101
01102
01103
01104 template<typename _Tp, typename _Class>
01105 struct _Maybe_wrap_member_pointer<_Tp _Class::*>
01106 {
01107 typedef _Mem_fn<_Tp _Class::*> type;
01108
01109 static type
01110 __do_wrap(_Tp _Class::* __pm)
01111 { return type(__pm); }
01112 };
01113
01114
01115 template<typename _Signature>
01116 struct _Bind;
01117
01118 template<typename _Functor, typename... _Bound_args>
01119 class _Bind<_Functor(_Bound_args...)>
01120 : public _Weak_result_type<_Functor>
01121 {
01122 typedef _Bind __self_type;
01123 typedef typename _Build_index_tuple<sizeof...(_Bound_args)>::__type
01124 _Bound_indexes;
01125
01126 _Functor _M_f;
01127 tuple<_Bound_args...> _M_bound_args;
01128
01129
01130 template<typename... _Args, int... _Indexes>
01131 typename result_of<
01132 _Functor(typename result_of<_Mu<_Bound_args>
01133 (_Bound_args, tuple<_Args...>)>::type...)
01134 >::type
01135 __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>)
01136 {
01137 return _M_f(_Mu<_Bound_args>()
01138 (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01139 }
01140
01141
01142 template<typename... _Args, int... _Indexes>
01143 typename result_of<
01144 const _Functor(typename result_of<_Mu<_Bound_args>
01145 (const _Bound_args, tuple<_Args...>)
01146 >::type...)>::type
01147 __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const
01148 {
01149 return _M_f(_Mu<_Bound_args>()
01150 (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01151 }
01152
01153
01154 template<typename... _Args, int... _Indexes>
01155 typename result_of<
01156 volatile _Functor(typename result_of<_Mu<_Bound_args>
01157 (volatile _Bound_args, tuple<_Args...>)
01158 >::type...)>::type
01159 __call(const tuple<_Args...>& __args,
01160 _Index_tuple<_Indexes...>) volatile
01161 {
01162 return _M_f(_Mu<_Bound_args>()
01163 (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01164 }
01165
01166
01167 template<typename... _Args, int... _Indexes>
01168 typename result_of<
01169 const volatile _Functor(typename result_of<_Mu<_Bound_args>
01170 (const volatile _Bound_args,
01171 tuple<_Args...>)
01172 >::type...)>::type
01173 __call(const tuple<_Args...>& __args,
01174 _Index_tuple<_Indexes...>) const volatile
01175 {
01176 return _M_f(_Mu<_Bound_args>()
01177 (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01178 }
01179
01180 public:
01181 explicit _Bind(_Functor __f, _Bound_args... __bound_args)
01182 : _M_f(__f), _M_bound_args(__bound_args...) { }
01183
01184
01185 template<typename... _Args>
01186 typename result_of<
01187 _Functor(typename result_of<_Mu<_Bound_args>
01188 (_Bound_args, tuple<_Args...>)>::type...)
01189 >::type
01190 operator()(_Args&... __args)
01191 {
01192 return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01193 }
01194
01195
01196 template<typename... _Args>
01197 typename result_of<
01198 const _Functor(typename result_of<_Mu<_Bound_args>
01199 (const _Bound_args, tuple<_Args...>)>::type...)
01200 >::type
01201 operator()(_Args&... __args) const
01202 {
01203 return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01204 }
01205
01206
01207
01208 template<typename... _Args>
01209 typename result_of<
01210 volatile _Functor(typename result_of<_Mu<_Bound_args>
01211 (volatile _Bound_args, tuple<_Args...>)>::type...)
01212 >::type
01213 operator()(_Args&... __args) volatile
01214 {
01215 return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01216 }
01217
01218
01219
01220 template<typename... _Args>
01221 typename result_of<
01222 const volatile _Functor(typename result_of<_Mu<_Bound_args>
01223 (const volatile _Bound_args,
01224 tuple<_Args...>)>::type...)
01225 >::type
01226 operator()(_Args&... __args) const volatile
01227 {
01228 return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01229 }
01230 };
01231
01232
01233 template<typename _Result, typename _Signature>
01234 struct _Bind_result;
01235
01236 template<typename _Result, typename _Functor, typename... _Bound_args>
01237 class _Bind_result<_Result, _Functor(_Bound_args...)>
01238 {
01239 typedef _Bind_result __self_type;
01240 typedef typename _Build_index_tuple<sizeof...(_Bound_args)>::__type
01241 _Bound_indexes;
01242
01243 _Functor _M_f;
01244 tuple<_Bound_args...> _M_bound_args;
01245
01246
01247 template<typename... _Args, int... _Indexes>
01248 _Result
01249 __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>)
01250 {
01251 return _M_f(_Mu<_Bound_args>()
01252 (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01253 }
01254
01255
01256 template<typename... _Args, int... _Indexes>
01257 _Result
01258 __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const
01259 {
01260 return _M_f(_Mu<_Bound_args>()
01261 (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01262 }
01263
01264
01265 template<typename... _Args, int... _Indexes>
01266 _Result
01267 __call(const tuple<_Args...>& __args,
01268 _Index_tuple<_Indexes...>) volatile
01269 {
01270 return _M_f(_Mu<_Bound_args>()
01271 (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01272 }
01273
01274
01275 template<typename... _Args, int... _Indexes>
01276 _Result
01277 __call(const tuple<_Args...>& __args,
01278 _Index_tuple<_Indexes...>) const volatile
01279 {
01280 return _M_f(_Mu<_Bound_args>()
01281 (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01282 }
01283
01284 public:
01285 typedef _Result result_type;
01286
01287 explicit
01288 _Bind_result(_Functor __f, _Bound_args... __bound_args)
01289 : _M_f(__f), _M_bound_args(__bound_args...) { }
01290
01291
01292 template<typename... _Args>
01293 result_type
01294 operator()(_Args&... __args)
01295 {
01296 return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01297 }
01298
01299
01300 template<typename... _Args>
01301 result_type
01302 operator()(_Args&... __args) const
01303 {
01304 return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01305 }
01306
01307
01308 template<typename... _Args>
01309 result_type
01310 operator()(_Args&... __args) volatile
01311 {
01312 return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01313 }
01314
01315
01316 template<typename... _Args>
01317 result_type
01318 operator()(_Args&... __args) const volatile
01319 {
01320 return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01321 }
01322 };
01323
01324
01325 template<typename _Signature>
01326 struct is_bind_expression<_Bind<_Signature> >
01327 { static const bool value = true; };
01328
01329 template<typename _Signature>
01330 const bool is_bind_expression<_Bind<_Signature> >::value;
01331
01332
01333 template<typename _Result, typename _Signature>
01334 struct is_bind_expression<_Bind_result<_Result, _Signature> >
01335 { static const bool value = true; };
01336
01337 template<typename _Result, typename _Signature>
01338 const bool is_bind_expression<_Bind_result<_Result, _Signature> >::value;
01339
01340
01341 template<typename _Functor, typename... _ArgTypes>
01342 inline
01343 _Bind<typename _Maybe_wrap_member_pointer<_Functor>::type(_ArgTypes...)>
01344 bind(_Functor __f, _ArgTypes... __args)
01345 {
01346 typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
01347 typedef typename __maybe_type::type __functor_type;
01348 typedef _Bind<__functor_type(_ArgTypes...)> __result_type;
01349 return __result_type(__maybe_type::__do_wrap(__f), __args...);
01350 }
01351
01352 template<typename _Result, typename _Functor, typename... _ArgTypes>
01353 inline
01354 _Bind_result<_Result,
01355 typename _Maybe_wrap_member_pointer<_Functor>::type
01356 (_ArgTypes...)>
01357 bind(_Functor __f, _ArgTypes... __args)
01358 {
01359 typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
01360 typedef typename __maybe_type::type __functor_type;
01361 typedef _Bind_result<_Result, __functor_type(_ArgTypes...)>
01362 __result_type;
01363 return __result_type(__maybe_type::__do_wrap(__f), __args...);
01364 }
01365
01366
01367
01368
01369
01370
01371 class bad_function_call : public std::exception { };
01372
01373
01374
01375
01376
01377
01378 struct _M_clear_type;
01379
01380
01381
01382
01383
01384
01385 template<typename _Tp>
01386 struct __is_location_invariant
01387 : integral_constant<bool,
01388 (is_pointer<_Tp>::value
01389 || is_member_pointer<_Tp>::value)>
01390 {
01391 };
01392
01393 class _Undefined_class;
01394
01395 union _Nocopy_types
01396 {
01397 void* _M_object;
01398 const void* _M_const_object;
01399 void (*_M_function_pointer)();
01400 void (_Undefined_class::*_M_member_pointer)();
01401 };
01402
01403 union _Any_data
01404 {
01405 void* _M_access() { return &_M_pod_data[0]; }
01406 const void* _M_access() const { return &_M_pod_data[0]; }
01407
01408 template<typename _Tp>
01409 _Tp&
01410 _M_access()
01411 { return *static_cast<_Tp*>(_M_access()); }
01412
01413 template<typename _Tp>
01414 const _Tp&
01415 _M_access() const
01416 { return *static_cast<const _Tp*>(_M_access()); }
01417
01418 _Nocopy_types _M_unused;
01419 char _M_pod_data[sizeof(_Nocopy_types)];
01420 };
01421
01422 enum _Manager_operation
01423 {
01424 __get_type_info,
01425 __get_functor_ptr,
01426 __clone_functor,
01427 __destroy_functor
01428 };
01429
01430
01431
01432 template<typename _Tp>
01433 struct _Simple_type_wrapper
01434 {
01435 _Simple_type_wrapper(_Tp __value) : __value(__value) { }
01436
01437 _Tp __value;
01438 };
01439
01440 template<typename _Tp>
01441 struct __is_location_invariant<_Simple_type_wrapper<_Tp> >
01442 : __is_location_invariant<_Tp>
01443 {
01444 };
01445
01446
01447
01448 template<typename _Functor>
01449 inline _Functor&
01450 __callable_functor(_Functor& __f)
01451 { return __f; }
01452
01453 template<typename _Member, typename _Class>
01454 inline _Mem_fn<_Member _Class::*>
01455 __callable_functor(_Member _Class::* &__p)
01456 { return mem_fn(__p); }
01457
01458 template<typename _Member, typename _Class>
01459 inline _Mem_fn<_Member _Class::*>
01460 __callable_functor(_Member _Class::* const &__p)
01461 { return mem_fn(__p); }
01462
01463 template<typename _Signature>
01464 class function;
01465
01466
01467 class _Function_base
01468 {
01469 public:
01470 static const std::size_t _M_max_size = sizeof(_Nocopy_types);
01471 static const std::size_t _M_max_align = __alignof__(_Nocopy_types);
01472
01473 template<typename _Functor>
01474 class _Base_manager
01475 {
01476 protected:
01477 static const bool __stored_locally =
01478 (__is_location_invariant<_Functor>::value
01479 && sizeof(_Functor) <= _M_max_size
01480 && __alignof__(_Functor) <= _M_max_align
01481 && (_M_max_align % __alignof__(_Functor) == 0));
01482
01483 typedef integral_constant<bool, __stored_locally> _Local_storage;
01484
01485
01486 static _Functor*
01487 _M_get_pointer(const _Any_data& __source)
01488 {
01489 const _Functor* __ptr =
01490 __stored_locally? &__source._M_access<_Functor>()
01491 : __source._M_access<_Functor*>();
01492 return const_cast<_Functor*>(__ptr);
01493 }
01494
01495
01496
01497 static void
01498 _M_clone(_Any_data& __dest, const _Any_data& __source, true_type)
01499 {
01500 new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
01501 }
01502
01503
01504
01505 static void
01506 _M_clone(_Any_data& __dest, const _Any_data& __source, false_type)
01507 {
01508 __dest._M_access<_Functor*>() =
01509 new _Functor(*__source._M_access<_Functor*>());
01510 }
01511
01512
01513
01514 static void
01515 _M_destroy(_Any_data& __victim, true_type)
01516 {
01517 __victim._M_access<_Functor>().~_Functor();
01518 }
01519
01520
01521 static void
01522 _M_destroy(_Any_data& __victim, false_type)
01523 {
01524 delete __victim._M_access<_Functor*>();
01525 }
01526
01527 public:
01528 static bool
01529 _M_manager(_Any_data& __dest, const _Any_data& __source,
01530 _Manager_operation __op)
01531 {
01532 switch (__op)
01533 {
01534 case __get_type_info:
01535 __dest._M_access<const type_info*>() = &typeid(_Functor);
01536 break;
01537
01538 case __get_functor_ptr:
01539 __dest._M_access<_Functor*>() = _M_get_pointer(__source);
01540 break;
01541
01542 case __clone_functor:
01543 _M_clone(__dest, __source, _Local_storage());
01544 break;
01545
01546 case __destroy_functor:
01547 _M_destroy(__dest, _Local_storage());
01548 break;
01549 }
01550 return false;
01551 }
01552
01553 static void
01554 _M_init_functor(_Any_data& __functor, const _Functor& __f)
01555 { _M_init_functor(__functor, __f, _Local_storage()); }
01556
01557 template<typename _Signature>
01558 static bool
01559 _M_not_empty_function(const function<_Signature>& __f)
01560 { return __f; }
01561
01562 template<typename _Tp>
01563 static bool
01564 _M_not_empty_function(const _Tp*& __fp)
01565 { return __fp; }
01566
01567 template<typename _Class, typename _Tp>
01568 static bool
01569 _M_not_empty_function(_Tp _Class::* const& __mp)
01570 { return __mp; }
01571
01572 template<typename _Tp>
01573 static bool
01574 _M_not_empty_function(const _Tp&)
01575 { return true; }
01576
01577 private:
01578 static void
01579 _M_init_functor(_Any_data& __functor, const _Functor& __f, true_type)
01580 { new (__functor._M_access()) _Functor(__f); }
01581
01582 static void
01583 _M_init_functor(_Any_data& __functor, const _Functor& __f, false_type)
01584 { __functor._M_access<_Functor*>() = new _Functor(__f); }
01585 };
01586
01587 template<typename _Functor>
01588 class _Ref_manager : public _Base_manager<_Functor*>
01589 {
01590 typedef _Function_base::_Base_manager<_Functor*> _Base;
01591
01592 public:
01593 static bool
01594 _M_manager(_Any_data& __dest, const _Any_data& __source,
01595 _Manager_operation __op)
01596 {
01597 switch (__op)
01598 {
01599 case __get_type_info:
01600 __dest._M_access<const type_info*>() = &typeid(_Functor);
01601 break;
01602
01603 case __get_functor_ptr:
01604 __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source);
01605 return is_const<_Functor>::value;
01606 break;
01607
01608 default:
01609 _Base::_M_manager(__dest, __source, __op);
01610 }
01611 return false;
01612 }
01613
01614 static void
01615 _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f)
01616 {
01617
01618 _Base::_M_init_functor(__functor, &__f.get());
01619 }
01620 };
01621
01622 _Function_base() : _M_manager(0) { }
01623
01624 ~_Function_base()
01625 {
01626 if (_M_manager)
01627 _M_manager(_M_functor, _M_functor, __destroy_functor);
01628 }
01629
01630
01631 bool _M_empty() const { return !_M_manager; }
01632
01633 typedef bool (*_Manager_type)(_Any_data&, const _Any_data&,
01634 _Manager_operation);
01635
01636 _Any_data _M_functor;
01637 _Manager_type _M_manager;
01638 };
01639
01640 template<typename _Signature, typename _Functor>
01641 class _Function_handler;
01642
01643 template<typename _Res, typename _Functor, typename... _ArgTypes>
01644 class _Function_handler<_Res(_ArgTypes...), _Functor>
01645 : public _Function_base::_Base_manager<_Functor>
01646 {
01647 typedef _Function_base::_Base_manager<_Functor> _Base;
01648
01649 public:
01650 static _Res
01651 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01652 {
01653 return (*_Base::_M_get_pointer(__functor))(__args...);
01654 }
01655 };
01656
01657 template<typename _Functor, typename... _ArgTypes>
01658 class _Function_handler<void(_ArgTypes...), _Functor>
01659 : public _Function_base::_Base_manager<_Functor>
01660 {
01661 typedef _Function_base::_Base_manager<_Functor> _Base;
01662
01663 public:
01664 static void
01665 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01666 {
01667 (*_Base::_M_get_pointer(__functor))(__args...);
01668 }
01669 };
01670
01671 template<typename _Res, typename _Functor, typename... _ArgTypes>
01672 class _Function_handler<_Res(_ArgTypes...), reference_wrapper<_Functor> >
01673 : public _Function_base::_Ref_manager<_Functor>
01674 {
01675 typedef _Function_base::_Ref_manager<_Functor> _Base;
01676
01677 public:
01678 static _Res
01679 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01680 {
01681 return
01682 __callable_functor(**_Base::_M_get_pointer(__functor))(__args...);
01683 }
01684 };
01685
01686 template<typename _Functor, typename... _ArgTypes>
01687 class _Function_handler<void(_ArgTypes...), reference_wrapper<_Functor> >
01688 : public _Function_base::_Ref_manager<_Functor>
01689 {
01690 typedef _Function_base::_Ref_manager<_Functor> _Base;
01691
01692 public:
01693 static void
01694 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01695 {
01696 __callable_functor(**_Base::_M_get_pointer(__functor))(__args...);
01697 }
01698 };
01699
01700 template<typename _Class, typename _Member, typename _Res,
01701 typename... _ArgTypes>
01702 class _Function_handler<_Res(_ArgTypes...), _Member _Class::*>
01703 : public _Function_handler<void(_ArgTypes...), _Member _Class::*>
01704 {
01705 typedef _Function_handler<void(_ArgTypes...), _Member _Class::*>
01706 _Base;
01707
01708 public:
01709 static _Res
01710 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01711 {
01712 return _GLIBCXX_TR1
01713 mem_fn(_Base::_M_get_pointer(__functor)->__value)(__args...);
01714 }
01715 };
01716
01717 template<typename _Class, typename _Member, typename... _ArgTypes>
01718 class _Function_handler<void(_ArgTypes...), _Member _Class::*>
01719 : public _Function_base::_Base_manager<
01720 _Simple_type_wrapper< _Member _Class::* > >
01721 {
01722 typedef _Member _Class::* _Functor;
01723 typedef _Simple_type_wrapper<_Functor> _Wrapper;
01724 typedef _Function_base::_Base_manager<_Wrapper> _Base;
01725
01726 public:
01727 static bool
01728 _M_manager(_Any_data& __dest, const _Any_data& __source,
01729 _Manager_operation __op)
01730 {
01731 switch (__op)
01732 {
01733 case __get_type_info:
01734 __dest._M_access<const type_info*>() = &typeid(_Functor);
01735 break;
01736
01737 case __get_functor_ptr:
01738 __dest._M_access<_Functor*>() =
01739 &_Base::_M_get_pointer(__source)->__value;
01740 break;
01741
01742 default:
01743 _Base::_M_manager(__dest, __source, __op);
01744 }
01745 return false;
01746 }
01747
01748 static void
01749 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01750 {
01751 _GLIBCXX_TR1
01752 mem_fn(_Base::_M_get_pointer(__functor)->__value)(__args...);
01753 }
01754 };
01755
01756
01757 template<typename _Res, typename... _ArgTypes>
01758 class function<_Res(_ArgTypes...)>
01759 : public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>,
01760 private _Function_base
01761 {
01762
01763 struct _Hidden_type
01764 {
01765 _Hidden_type* _M_bool;
01766 };
01767
01768
01769 typedef _Hidden_type* _Hidden_type::* _Safe_bool;
01770
01771 typedef _Res _Signature_type(_ArgTypes...);
01772
01773 struct _Useless { };
01774
01775 public:
01776 typedef _Res result_type;
01777
01778
01779
01780
01781
01782
01783
01784 function() : _Function_base() { }
01785
01786
01787
01788
01789
01790 function(_M_clear_type*) : _Function_base() { }
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800 function(const function& __x);
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818 template<typename _Functor>
01819 function(_Functor __f,
01820 typename __gnu_cxx::__enable_if<
01821 !is_integral<_Functor>::value, _Useless>::__type
01822 = _Useless());
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836 function&
01837 operator=(const function& __x)
01838 {
01839 function(__x).swap(*this);
01840 return *this;
01841 }
01842
01843
01844
01845
01846
01847
01848
01849
01850 function&
01851 operator=(_M_clear_type*)
01852 {
01853 if (_M_manager)
01854 {
01855 _M_manager(_M_functor, _M_functor, __destroy_functor);
01856 _M_manager = 0;
01857 _M_invoker = 0;
01858 }
01859 return *this;
01860 }
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878 template<typename _Functor>
01879 typename __gnu_cxx::__enable_if<!is_integral<_Functor>::value,
01880 function&>::__type
01881 operator=(_Functor __f)
01882 {
01883 function(__f).swap(*this);
01884 return *this;
01885 }
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896 void swap(function& __x)
01897 {
01898 _Any_data __old_functor = _M_functor;
01899 _M_functor = __x._M_functor;
01900 __x._M_functor = __old_functor;
01901 _Manager_type __old_manager = _M_manager;
01902 _M_manager = __x._M_manager;
01903 __x._M_manager = __old_manager;
01904 _Invoker_type __old_invoker = _M_invoker;
01905 _M_invoker = __x._M_invoker;
01906 __x._M_invoker = __old_invoker;
01907 }
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919 operator _Safe_bool() const
01920 {
01921 if (_M_empty())
01922 return 0;
01923 else
01924 return &_Hidden_type::_M_bool;
01925 }
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937 _Res operator()(_ArgTypes... __args) const;
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949 const type_info& target_type() const;
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960 template<typename _Functor> _Functor* target();
01961
01962
01963 template<typename _Functor> const _Functor* target() const;
01964
01965 private:
01966
01967 template<typename _Function>
01968 void operator==(const function<_Function>&) const;
01969 template<typename _Function>
01970 void operator!=(const function<_Function>&) const;
01971
01972 typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...);
01973 _Invoker_type _M_invoker;
01974 };
01975
01976 template<typename _Res, typename... _ArgTypes>
01977 function<_Res(_ArgTypes...)>::
01978 function(const function& __x)
01979 : _Function_base()
01980 {
01981 if (__x)
01982 {
01983 _M_invoker = __x._M_invoker;
01984 _M_manager = __x._M_manager;
01985 __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
01986 }
01987 }
01988
01989 template<typename _Res, typename... _ArgTypes>
01990 template<typename _Functor>
01991 function<_Res(_ArgTypes...)>::
01992 function(_Functor __f,
01993 typename __gnu_cxx::__enable_if<
01994 !is_integral<_Functor>::value, _Useless>::__type)
01995 : _Function_base()
01996 {
01997 typedef _Function_handler<_Signature_type, _Functor> _My_handler;
01998
01999 if (_My_handler::_M_not_empty_function(__f))
02000 {
02001 _M_invoker = &_My_handler::_M_invoke;
02002 _M_manager = &_My_handler::_M_manager;
02003 _My_handler::_M_init_functor(_M_functor, __f);
02004 }
02005 }
02006
02007 template<typename _Res, typename... _ArgTypes>
02008 _Res
02009 function<_Res(_ArgTypes...)>::
02010 operator()(_ArgTypes... __args) const
02011 {
02012 if (_M_empty())
02013 {
02014 #if __EXCEPTIONS
02015 throw bad_function_call();
02016 #else
02017 __builtin_abort();
02018 #endif
02019 }
02020 return _M_invoker(_M_functor, __args...);
02021 }
02022
02023 template<typename _Res, typename... _ArgTypes>
02024 const type_info&
02025 function<_Res(_ArgTypes...)>::
02026 target_type() const
02027 {
02028 if (_M_manager)
02029 {
02030 _Any_data __typeinfo_result;
02031 _M_manager(__typeinfo_result, _M_functor, __get_type_info);
02032 return *__typeinfo_result._M_access<const type_info*>();
02033 }
02034 else
02035 return typeid(void);
02036 }
02037
02038 template<typename _Res, typename... _ArgTypes>
02039 template<typename _Functor>
02040 _Functor*
02041 function<_Res(_ArgTypes...)>::
02042 target()
02043 {
02044 if (typeid(_Functor) == target_type() && _M_manager)
02045 {
02046 _Any_data __ptr;
02047 if (_M_manager(__ptr, _M_functor, __get_functor_ptr)
02048 && !is_const<_Functor>::value)
02049 return 0;
02050 else
02051 return __ptr._M_access<_Functor*>();
02052 }
02053 else
02054 return 0;
02055 }
02056
02057 template<typename _Res, typename... _ArgTypes>
02058 template<typename _Functor>
02059 const _Functor*
02060 function<_Res(_ArgTypes...)>::
02061 target() const
02062 {
02063 if (typeid(_Functor) == target_type() && _M_manager)
02064 {
02065 _Any_data __ptr;
02066 _M_manager(__ptr, _M_functor, __get_functor_ptr);
02067 return __ptr._M_access<const _Functor*>();
02068 }
02069 else
02070 return 0;
02071 }
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082 template<typename _Signature>
02083 inline bool
02084 operator==(const function<_Signature>& __f, _M_clear_type*)
02085 { return !__f; }
02086
02087
02088 template<typename _Signature>
02089 inline bool
02090 operator==(_M_clear_type*, const function<_Signature>& __f)
02091 { return !__f; }
02092
02093
02094
02095
02096
02097
02098
02099
02100 template<typename _Signature>
02101 inline bool
02102 operator!=(const function<_Signature>& __f, _M_clear_type*)
02103 { return __f; }
02104
02105
02106 template<typename _Signature>
02107 inline bool
02108 operator!=(_M_clear_type*, const function<_Signature>& __f)
02109 { return __f; }
02110
02111
02112
02113
02114
02115
02116
02117
02118 template<typename _Signature>
02119 inline void
02120 swap(function<_Signature>& __x, function<_Signature>& __y)
02121 { __x.swap(__y); }
02122
02123 _GLIBCXX_END_NAMESPACE_TR1
02124 }