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