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