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