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