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 public:
01479 virtual ~bad_function_call() throw();
01480 };
01481
01482
01483
01484
01485
01486
01487 template<typename _Tp>
01488 struct __is_location_invariant
01489 : integral_constant<bool, (is_pointer<_Tp>::value
01490 || is_member_pointer<_Tp>::value)>
01491 { };
01492
01493 class _Undefined_class;
01494
01495 union _Nocopy_types
01496 {
01497 void* _M_object;
01498 const void* _M_const_object;
01499 void (*_M_function_pointer)();
01500 void (_Undefined_class::*_M_member_pointer)();
01501 };
01502
01503 union _Any_data
01504 {
01505 void* _M_access() { return &_M_pod_data[0]; }
01506 const void* _M_access() const { return &_M_pod_data[0]; }
01507
01508 template<typename _Tp>
01509 _Tp&
01510 _M_access()
01511 { return *static_cast<_Tp*>(_M_access()); }
01512
01513 template<typename _Tp>
01514 const _Tp&
01515 _M_access() const
01516 { return *static_cast<const _Tp*>(_M_access()); }
01517
01518 _Nocopy_types _M_unused;
01519 char _M_pod_data[sizeof(_Nocopy_types)];
01520 };
01521
01522 enum _Manager_operation
01523 {
01524 __get_type_info,
01525 __get_functor_ptr,
01526 __clone_functor,
01527 __destroy_functor
01528 };
01529
01530
01531
01532 template<typename _Tp>
01533 struct _Simple_type_wrapper
01534 {
01535 _Simple_type_wrapper(_Tp __value) : __value(__value) { }
01536
01537 _Tp __value;
01538 };
01539
01540 template<typename _Tp>
01541 struct __is_location_invariant<_Simple_type_wrapper<_Tp> >
01542 : __is_location_invariant<_Tp>
01543 { };
01544
01545
01546
01547 template<typename _Functor>
01548 inline _Functor&
01549 __callable_functor(_Functor& __f)
01550 { return __f; }
01551
01552 template<typename _Member, typename _Class>
01553 inline _Mem_fn<_Member _Class::*>
01554 __callable_functor(_Member _Class::* &__p)
01555 { return mem_fn(__p); }
01556
01557 template<typename _Member, typename _Class>
01558 inline _Mem_fn<_Member _Class::*>
01559 __callable_functor(_Member _Class::* const &__p)
01560 { return mem_fn(__p); }
01561
01562 template<typename _Signature>
01563 class function;
01564
01565
01566 class _Function_base
01567 {
01568 public:
01569 static const std::size_t _M_max_size = sizeof(_Nocopy_types);
01570 static const std::size_t _M_max_align = __alignof__(_Nocopy_types);
01571
01572 template<typename _Functor>
01573 class _Base_manager
01574 {
01575 protected:
01576 static const bool __stored_locally =
01577 (__is_location_invariant<_Functor>::value
01578 && sizeof(_Functor) <= _M_max_size
01579 && __alignof__(_Functor) <= _M_max_align
01580 && (_M_max_align % __alignof__(_Functor) == 0));
01581
01582 typedef integral_constant<bool, __stored_locally> _Local_storage;
01583
01584
01585 static _Functor*
01586 _M_get_pointer(const _Any_data& __source)
01587 {
01588 const _Functor* __ptr =
01589 __stored_locally? &__source._M_access<_Functor>()
01590 : __source._M_access<_Functor*>();
01591 return const_cast<_Functor*>(__ptr);
01592 }
01593
01594
01595
01596 static void
01597 _M_clone(_Any_data& __dest, const _Any_data& __source, true_type)
01598 {
01599 new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
01600 }
01601
01602
01603
01604 static void
01605 _M_clone(_Any_data& __dest, const _Any_data& __source, false_type)
01606 {
01607 __dest._M_access<_Functor*>() =
01608 new _Functor(*__source._M_access<_Functor*>());
01609 }
01610
01611
01612
01613 static void
01614 _M_destroy(_Any_data& __victim, true_type)
01615 {
01616 __victim._M_access<_Functor>().~_Functor();
01617 }
01618
01619
01620 static void
01621 _M_destroy(_Any_data& __victim, false_type)
01622 {
01623 delete __victim._M_access<_Functor*>();
01624 }
01625
01626 public:
01627 static bool
01628 _M_manager(_Any_data& __dest, const _Any_data& __source,
01629 _Manager_operation __op)
01630 {
01631 switch (__op)
01632 {
01633 #ifdef __GXX_RTTI
01634 case __get_type_info:
01635 __dest._M_access<const type_info*>() = &typeid(_Functor);
01636 break;
01637 #endif
01638 case __get_functor_ptr:
01639 __dest._M_access<_Functor*>() = _M_get_pointer(__source);
01640 break;
01641
01642 case __clone_functor:
01643 _M_clone(__dest, __source, _Local_storage());
01644 break;
01645
01646 case __destroy_functor:
01647 _M_destroy(__dest, _Local_storage());
01648 break;
01649 }
01650 return false;
01651 }
01652
01653 static void
01654 _M_init_functor(_Any_data& __functor, _Functor&& __f)
01655 { _M_init_functor(__functor, std::move(__f), _Local_storage()); }
01656
01657 template<typename _Signature>
01658 static bool
01659 _M_not_empty_function(const function<_Signature>& __f)
01660 { return static_cast<bool>(__f); }
01661
01662 template<typename _Tp>
01663 static bool
01664 _M_not_empty_function(const _Tp*& __fp)
01665 { return __fp; }
01666
01667 template<typename _Class, typename _Tp>
01668 static bool
01669 _M_not_empty_function(_Tp _Class::* const& __mp)
01670 { return __mp; }
01671
01672 template<typename _Tp>
01673 static bool
01674 _M_not_empty_function(const _Tp&)
01675 { return true; }
01676
01677 private:
01678 static void
01679 _M_init_functor(_Any_data& __functor, _Functor&& __f, true_type)
01680 { new (__functor._M_access()) _Functor(std::move(__f)); }
01681
01682 static void
01683 _M_init_functor(_Any_data& __functor, _Functor&& __f, false_type)
01684 { __functor._M_access<_Functor*>() = new _Functor(std::move(__f)); }
01685 };
01686
01687 template<typename _Functor>
01688 class _Ref_manager : public _Base_manager<_Functor*>
01689 {
01690 typedef _Function_base::_Base_manager<_Functor*> _Base;
01691
01692 public:
01693 static bool
01694 _M_manager(_Any_data& __dest, const _Any_data& __source,
01695 _Manager_operation __op)
01696 {
01697 switch (__op)
01698 {
01699 #ifdef __GXX_RTTI
01700 case __get_type_info:
01701 __dest._M_access<const type_info*>() = &typeid(_Functor);
01702 break;
01703 #endif
01704 case __get_functor_ptr:
01705 __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source);
01706 return is_const<_Functor>::value;
01707 break;
01708
01709 default:
01710 _Base::_M_manager(__dest, __source, __op);
01711 }
01712 return false;
01713 }
01714
01715 static void
01716 _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f)
01717 {
01718
01719 _Base::_M_init_functor(__functor, &__f.get());
01720 }
01721 };
01722
01723 _Function_base() : _M_manager(0) { }
01724
01725 ~_Function_base()
01726 {
01727 if (_M_manager)
01728 _M_manager(_M_functor, _M_functor, __destroy_functor);
01729 }
01730
01731
01732 bool _M_empty() const { return !_M_manager; }
01733
01734 typedef bool (*_Manager_type)(_Any_data&, const _Any_data&,
01735 _Manager_operation);
01736
01737 _Any_data _M_functor;
01738 _Manager_type _M_manager;
01739 };
01740
01741 template<typename _Signature, typename _Functor>
01742 class _Function_handler;
01743
01744 template<typename _Res, typename _Functor, typename... _ArgTypes>
01745 class _Function_handler<_Res(_ArgTypes...), _Functor>
01746 : public _Function_base::_Base_manager<_Functor>
01747 {
01748 typedef _Function_base::_Base_manager<_Functor> _Base;
01749
01750 public:
01751 static _Res
01752 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01753 {
01754 return (*_Base::_M_get_pointer(__functor))(
01755 std::forward<_ArgTypes>(__args)...);
01756 }
01757 };
01758
01759 template<typename _Functor, typename... _ArgTypes>
01760 class _Function_handler<void(_ArgTypes...), _Functor>
01761 : public _Function_base::_Base_manager<_Functor>
01762 {
01763 typedef _Function_base::_Base_manager<_Functor> _Base;
01764
01765 public:
01766 static void
01767 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01768 {
01769 (*_Base::_M_get_pointer(__functor))(
01770 std::forward<_ArgTypes>(__args)...);
01771 }
01772 };
01773
01774 template<typename _Res, typename _Functor, typename... _ArgTypes>
01775 class _Function_handler<_Res(_ArgTypes...), reference_wrapper<_Functor> >
01776 : public _Function_base::_Ref_manager<_Functor>
01777 {
01778 typedef _Function_base::_Ref_manager<_Functor> _Base;
01779
01780 public:
01781 static _Res
01782 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01783 {
01784 return __callable_functor(**_Base::_M_get_pointer(__functor))(
01785 std::forward<_ArgTypes>(__args)...);
01786 }
01787 };
01788
01789 template<typename _Functor, typename... _ArgTypes>
01790 class _Function_handler<void(_ArgTypes...), reference_wrapper<_Functor> >
01791 : public _Function_base::_Ref_manager<_Functor>
01792 {
01793 typedef _Function_base::_Ref_manager<_Functor> _Base;
01794
01795 public:
01796 static void
01797 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01798 {
01799 __callable_functor(**_Base::_M_get_pointer(__functor))(
01800 std::forward<_ArgTypes>(__args)...);
01801 }
01802 };
01803
01804 template<typename _Class, typename _Member, typename _Res,
01805 typename... _ArgTypes>
01806 class _Function_handler<_Res(_ArgTypes...), _Member _Class::*>
01807 : public _Function_handler<void(_ArgTypes...), _Member _Class::*>
01808 {
01809 typedef _Function_handler<void(_ArgTypes...), _Member _Class::*>
01810 _Base;
01811
01812 public:
01813 static _Res
01814 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01815 {
01816 return mem_fn(_Base::_M_get_pointer(__functor)->__value)(
01817 std::forward<_ArgTypes>(__args)...);
01818 }
01819 };
01820
01821 template<typename _Class, typename _Member, typename... _ArgTypes>
01822 class _Function_handler<void(_ArgTypes...), _Member _Class::*>
01823 : public _Function_base::_Base_manager<
01824 _Simple_type_wrapper< _Member _Class::* > >
01825 {
01826 typedef _Member _Class::* _Functor;
01827 typedef _Simple_type_wrapper<_Functor> _Wrapper;
01828 typedef _Function_base::_Base_manager<_Wrapper> _Base;
01829
01830 public:
01831 static bool
01832 _M_manager(_Any_data& __dest, const _Any_data& __source,
01833 _Manager_operation __op)
01834 {
01835 switch (__op)
01836 {
01837 #ifdef __GXX_RTTI
01838 case __get_type_info:
01839 __dest._M_access<const type_info*>() = &typeid(_Functor);
01840 break;
01841 #endif
01842 case __get_functor_ptr:
01843 __dest._M_access<_Functor*>() =
01844 &_Base::_M_get_pointer(__source)->__value;
01845 break;
01846
01847 default:
01848 _Base::_M_manager(__dest, __source, __op);
01849 }
01850 return false;
01851 }
01852
01853 static void
01854 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01855 {
01856 mem_fn(_Base::_M_get_pointer(__functor)->__value)(
01857 std::forward<_ArgTypes>(__args)...);
01858 }
01859 };
01860
01861
01862
01863
01864
01865
01866
01867 template<typename _Res, typename... _ArgTypes>
01868 class function<_Res(_ArgTypes...)>
01869 : public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>,
01870 private _Function_base
01871 {
01872 typedef _Res _Signature_type(_ArgTypes...);
01873
01874 struct _Useless { };
01875
01876 public:
01877 typedef _Res result_type;
01878
01879
01880
01881
01882
01883
01884
01885 function() : _Function_base() { }
01886
01887
01888
01889
01890
01891 function(nullptr_t) : _Function_base() { }
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901 function(const function& __x);
01902
01903
01904
01905
01906
01907
01908
01909
01910 function(function&& __x) : _Function_base()
01911 {
01912 __x.swap(*this);
01913 }
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933 template<typename _Functor>
01934 function(_Functor __f,
01935 typename enable_if<
01936 !is_integral<_Functor>::value, _Useless>::type
01937 = _Useless());
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951 function&
01952 operator=(const function& __x)
01953 {
01954 function(__x).swap(*this);
01955 return *this;
01956 }
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969 function&
01970 operator=(function&& __x)
01971 {
01972 function(std::move(__x)).swap(*this);
01973 return *this;
01974 }
01975
01976
01977
01978
01979
01980
01981
01982
01983 function&
01984 operator=(nullptr_t)
01985 {
01986 if (_M_manager)
01987 {
01988 _M_manager(_M_functor, _M_functor, __destroy_functor);
01989 _M_manager = 0;
01990 _M_invoker = 0;
01991 }
01992 return *this;
01993 }
01994
01995
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011 template<typename _Functor>
02012 typename enable_if<!is_integral<_Functor>::value, function&>::type
02013 operator=(_Functor&& __f)
02014 {
02015 function(std::forward<_Functor>(__f)).swap(*this);
02016 return *this;
02017 }
02018
02019
02020 template<typename _Functor>
02021 typename enable_if<!is_integral<_Functor>::value, function&>::type
02022 operator=(reference_wrapper<_Functor> __f)
02023 {
02024 function(__f).swap(*this);
02025 return *this;
02026 }
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037 void swap(function& __x)
02038 {
02039 std::swap(_M_functor, __x._M_functor);
02040 std::swap(_M_manager, __x._M_manager);
02041 std::swap(_M_invoker, __x._M_invoker);
02042 }
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065 explicit operator bool() const
02066 { return !_M_empty(); }
02067
02068
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078 _Res operator()(_ArgTypes... __args) const;
02079
02080 #ifdef __GXX_RTTI
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091 const type_info& target_type() const;
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102 template<typename _Functor> _Functor* target();
02103
02104
02105 template<typename _Functor> const _Functor* target() const;
02106 #endif
02107
02108 private:
02109 typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...);
02110 _Invoker_type _M_invoker;
02111 };
02112
02113
02114 template<typename _Res, typename... _ArgTypes>
02115 function<_Res(_ArgTypes...)>::
02116 function(const function& __x)
02117 : _Function_base()
02118 {
02119 if (static_cast<bool>(__x))
02120 {
02121 _M_invoker = __x._M_invoker;
02122 _M_manager = __x._M_manager;
02123 __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
02124 }
02125 }
02126
02127 template<typename _Res, typename... _ArgTypes>
02128 template<typename _Functor>
02129 function<_Res(_ArgTypes...)>::
02130 function(_Functor __f,
02131 typename enable_if<
02132 !is_integral<_Functor>::value, _Useless>::type)
02133 : _Function_base()
02134 {
02135 typedef _Function_handler<_Signature_type, _Functor> _My_handler;
02136
02137 if (_My_handler::_M_not_empty_function(__f))
02138 {
02139 _M_invoker = &_My_handler::_M_invoke;
02140 _M_manager = &_My_handler::_M_manager;
02141 _My_handler::_M_init_functor(_M_functor, std::move(__f));
02142 }
02143 }
02144
02145 template<typename _Res, typename... _ArgTypes>
02146 _Res
02147 function<_Res(_ArgTypes...)>::
02148 operator()(_ArgTypes... __args) const
02149 {
02150 if (_M_empty())
02151 __throw_bad_function_call();
02152 return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
02153 }
02154
02155 #ifdef __GXX_RTTI
02156 template<typename _Res, typename... _ArgTypes>
02157 const type_info&
02158 function<_Res(_ArgTypes...)>::
02159 target_type() const
02160 {
02161 if (_M_manager)
02162 {
02163 _Any_data __typeinfo_result;
02164 _M_manager(__typeinfo_result, _M_functor, __get_type_info);
02165 return *__typeinfo_result._M_access<const type_info*>();
02166 }
02167 else
02168 return typeid(void);
02169 }
02170
02171 template<typename _Res, typename... _ArgTypes>
02172 template<typename _Functor>
02173 _Functor*
02174 function<_Res(_ArgTypes...)>::
02175 target()
02176 {
02177 if (typeid(_Functor) == target_type() && _M_manager)
02178 {
02179 _Any_data __ptr;
02180 if (_M_manager(__ptr, _M_functor, __get_functor_ptr)
02181 && !is_const<_Functor>::value)
02182 return 0;
02183 else
02184 return __ptr._M_access<_Functor*>();
02185 }
02186 else
02187 return 0;
02188 }
02189
02190 template<typename _Res, typename... _ArgTypes>
02191 template<typename _Functor>
02192 const _Functor*
02193 function<_Res(_ArgTypes...)>::
02194 target() const
02195 {
02196 if (typeid(_Functor) == target_type() && _M_manager)
02197 {
02198 _Any_data __ptr;
02199 _M_manager(__ptr, _M_functor, __get_functor_ptr);
02200 return __ptr._M_access<const _Functor*>();
02201 }
02202 else
02203 return 0;
02204 }
02205 #endif
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216 template<typename _Res, typename... _Args>
02217 inline bool
02218 operator==(const function<_Res(_Args...)>& __f, nullptr_t)
02219 { return !static_cast<bool>(__f); }
02220
02221
02222 template<typename _Res, typename... _Args>
02223 inline bool
02224 operator==(nullptr_t, const function<_Res(_Args...)>& __f)
02225 { return !static_cast<bool>(__f); }
02226
02227
02228
02229
02230
02231
02232
02233
02234 template<typename _Res, typename... _Args>
02235 inline bool
02236 operator!=(const function<_Res(_Args...)>& __f, nullptr_t)
02237 { return static_cast<bool>(__f); }
02238
02239
02240 template<typename _Res, typename... _Args>
02241 inline bool
02242 operator!=(nullptr_t, const function<_Res(_Args...)>& __f)
02243 { return static_cast<bool>(__f); }
02244
02245
02246
02247
02248
02249
02250
02251
02252 template<typename _Res, typename... _Args>
02253 inline void
02254 swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y)
02255 { __x.swap(__y); }
02256
02257 _GLIBCXX_END_NAMESPACE_VERSION
02258 }
02259
02260 #endif // __GXX_EXPERIMENTAL_CXX0X__
02261
02262 #endif // _GLIBCXX_FUNCTIONAL