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 #ifndef _TR1_FUNCTIONAL
00035 #define _TR1_FUNCTIONAL 1
00036
00037 #pragma GCC system_header
00038
00039 #include "../functional"
00040 #include <typeinfo>
00041 #include <tr1/type_traits>
00042 #include <ext/type_traits.h>
00043 #include <cstdlib>
00044 #include <tr1/tuple>
00045
00046 namespace std
00047 {
00048 _GLIBCXX_BEGIN_NAMESPACE(tr1)
00049
00050 template<typename _MemberPointer>
00051 class _Mem_fn;
00052
00053
00054
00055
00056
00057
00058
00059
00060 template<typename _Tp>
00061 class _Has_result_type_helper : __sfinae_types
00062 {
00063 template<typename _Up>
00064 struct _Wrap_type
00065 { };
00066
00067 template<typename _Up>
00068 static __one __test(_Wrap_type<typename _Up::result_type>*);
00069
00070 template<typename _Up>
00071 static __two __test(...);
00072
00073 public:
00074 static const bool value = sizeof(__test<_Tp>(0)) == 1;
00075 };
00076
00077 template<typename _Tp>
00078 struct _Has_result_type
00079 : integral_constant<
00080 bool,
00081 _Has_result_type_helper<typename remove_cv<_Tp>::type>::value>
00082 { };
00083
00084
00085
00086
00087
00088
00089 template<bool _Has_result_type, typename _Functor>
00090 struct _Maybe_get_result_type
00091 { };
00092
00093 template<typename _Functor>
00094 struct _Maybe_get_result_type<true, _Functor>
00095 {
00096 typedef typename _Functor::result_type result_type;
00097 };
00098
00099
00100
00101
00102
00103
00104
00105 template<typename _Functor>
00106 struct _Weak_result_type_impl
00107 : _Maybe_get_result_type<_Has_result_type<_Functor>::value, _Functor>
00108 {
00109 };
00110
00111
00112
00113
00114
00115
00116
00117 template<typename _Functor>
00118 struct _Weak_result_type
00119 : _Weak_result_type_impl<typename remove_cv<_Functor>::type>
00120 {
00121 };
00122
00123 template<typename _Signature>
00124 class result_of;
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 template<bool _Has_result_type, typename _Signature>
00135 struct _Result_of_impl;
00136
00137
00138 template<typename _Res, typename _Class, typename _T1>
00139 struct _Result_of_impl<false, _Res _Class::*(_T1)>
00140 {
00141 typedef typename _Mem_fn<_Res _Class::*>
00142 ::template _Result_type<_T1>::type type;
00143 };
00144
00145
00146
00147
00148
00149
00150 template<typename _Tp>
00151 struct _Derives_from_unary_function : __sfinae_types
00152 {
00153 private:
00154 template<typename _T1, typename _Res>
00155 static __one __test(const volatile unary_function<_T1, _Res>*);
00156
00157
00158
00159 static __two __test(...);
00160
00161 public:
00162 static const bool value = sizeof(__test((_Tp*)0)) == 1;
00163 };
00164
00165
00166
00167
00168
00169
00170 template<typename _Tp>
00171 struct _Derives_from_binary_function : __sfinae_types
00172 {
00173 private:
00174 template<typename _T1, typename _T2, typename _Res>
00175 static __one __test(const volatile binary_function<_T1, _T2, _Res>*);
00176
00177
00178
00179 static __two __test(...);
00180
00181 public:
00182 static const bool value = sizeof(__test((_Tp*)0)) == 1;
00183 };
00184
00185
00186
00187
00188
00189
00190 template<typename _Tp, bool _IsFunctionType = is_function<_Tp>::value>
00191 struct _Function_to_function_pointer
00192 {
00193 typedef _Tp type;
00194 };
00195
00196 template<typename _Tp>
00197 struct _Function_to_function_pointer<_Tp, true>
00198 {
00199 typedef _Tp* type;
00200 };
00201
00202
00203
00204
00205
00206
00207
00208
00209 template<bool _Unary, bool _Binary, typename _Tp>
00210 struct _Reference_wrapper_base_impl;
00211
00212
00213 template<typename _Tp>
00214 struct _Reference_wrapper_base_impl<false, false, _Tp>
00215 : _Weak_result_type<_Tp>
00216 { };
00217
00218
00219 template<typename _Tp>
00220 struct _Reference_wrapper_base_impl<true, false, _Tp>
00221 : unary_function<typename _Tp::argument_type,
00222 typename _Tp::result_type>
00223 { };
00224
00225
00226 template<typename _Tp>
00227 struct _Reference_wrapper_base_impl<false, true, _Tp>
00228 : binary_function<typename _Tp::first_argument_type,
00229 typename _Tp::second_argument_type,
00230 typename _Tp::result_type>
00231 { };
00232
00233
00234
00235 template<typename _Tp>
00236 struct _Reference_wrapper_base_impl<true, true, _Tp>
00237 : unary_function<typename _Tp::argument_type,
00238 typename _Tp::result_type>,
00239 binary_function<typename _Tp::first_argument_type,
00240 typename _Tp::second_argument_type,
00241 typename _Tp::result_type>
00242 {
00243 typedef typename _Tp::result_type result_type;
00244 };
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 template<typename _Tp>
00255 struct _Reference_wrapper_base
00256 : _Reference_wrapper_base_impl<
00257 _Derives_from_unary_function<_Tp>::value,
00258 _Derives_from_binary_function<_Tp>::value,
00259 _Tp>
00260 { };
00261
00262
00263 template<typename _Res, typename _T1>
00264 struct _Reference_wrapper_base<_Res(_T1)>
00265 : unary_function<_T1, _Res>
00266 { };
00267
00268
00269 template<typename _Res, typename _T1, typename _T2>
00270 struct _Reference_wrapper_base<_Res(_T1, _T2)>
00271 : binary_function<_T1, _T2, _Res>
00272 { };
00273
00274
00275 template<typename _Res, typename _T1>
00276 struct _Reference_wrapper_base<_Res(*)(_T1)>
00277 : unary_function<_T1, _Res>
00278 { };
00279
00280
00281 template<typename _Res, typename _T1, typename _T2>
00282 struct _Reference_wrapper_base<_Res(*)(_T1, _T2)>
00283 : binary_function<_T1, _T2, _Res>
00284 { };
00285
00286
00287 template<typename _Res, typename _T1>
00288 struct _Reference_wrapper_base<_Res (_T1::*)()>
00289 : unary_function<_T1*, _Res>
00290 { };
00291
00292
00293 template<typename _Res, typename _T1, typename _T2>
00294 struct _Reference_wrapper_base<_Res (_T1::*)(_T2)>
00295 : binary_function<_T1*, _T2, _Res>
00296 { };
00297
00298
00299 template<typename _Res, typename _T1>
00300 struct _Reference_wrapper_base<_Res (_T1::*)() const>
00301 : unary_function<const _T1*, _Res>
00302 { };
00303
00304
00305 template<typename _Res, typename _T1, typename _T2>
00306 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const>
00307 : binary_function<const _T1*, _T2, _Res>
00308 { };
00309
00310
00311 template<typename _Res, typename _T1>
00312 struct _Reference_wrapper_base<_Res (_T1::*)() volatile>
00313 : unary_function<volatile _T1*, _Res>
00314 { };
00315
00316
00317 template<typename _Res, typename _T1, typename _T2>
00318 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile>
00319 : binary_function<volatile _T1*, _T2, _Res>
00320 { };
00321
00322
00323 template<typename _Res, typename _T1>
00324 struct _Reference_wrapper_base<_Res (_T1::*)() const volatile>
00325 : unary_function<const volatile _T1*, _Res>
00326 { };
00327
00328
00329 template<typename _Res, typename _T1, typename _T2>
00330 struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile>
00331 : binary_function<const volatile _T1*, _T2, _Res>
00332 { };
00333
00334 template<typename _Tp>
00335 class reference_wrapper
00336 : public _Reference_wrapper_base<typename remove_cv<_Tp>::type>
00337 {
00338
00339
00340 typedef typename _Function_to_function_pointer<_Tp>::type
00341 _M_func_type;
00342
00343 _Tp* _M_data;
00344 public:
00345 typedef _Tp type;
00346 explicit reference_wrapper(_Tp& __indata): _M_data(&__indata)
00347 { }
00348
00349 reference_wrapper(const reference_wrapper<_Tp>& __inref):
00350 _M_data(__inref._M_data)
00351 { }
00352
00353 reference_wrapper&
00354 operator=(const reference_wrapper<_Tp>& __inref)
00355 {
00356 _M_data = __inref._M_data;
00357 return *this;
00358 }
00359
00360 operator _Tp&() const
00361 { return this->get(); }
00362
00363 _Tp&
00364 get() const
00365 { return *_M_data; }
00366
00367 #define _GLIBCXX_REPEAT_HEADER <tr1/ref_wrap_iterate.h>
00368 #include <tr1/repeat.h>
00369 #undef _GLIBCXX_REPEAT_HEADER
00370 };
00371
00372
00373
00374 template<typename _Tp>
00375 inline reference_wrapper<_Tp>
00376 ref(_Tp& __t)
00377 { return reference_wrapper<_Tp>(__t); }
00378
00379
00380 template<typename _Tp>
00381 inline reference_wrapper<const _Tp>
00382 cref(const _Tp& __t)
00383 { return reference_wrapper<const _Tp>(__t); }
00384
00385 template<typename _Tp>
00386 inline reference_wrapper<_Tp>
00387 ref(reference_wrapper<_Tp> __t)
00388 { return ref(__t.get()); }
00389
00390 template<typename _Tp>
00391 inline reference_wrapper<const _Tp>
00392 cref(reference_wrapper<_Tp> __t)
00393 { return cref(__t.get()); }
00394
00395 template<typename _Tp, bool>
00396 struct _Mem_fn_const_or_non
00397 {
00398 typedef const _Tp& type;
00399 };
00400
00401 template<typename _Tp>
00402 struct _Mem_fn_const_or_non<_Tp, false>
00403 {
00404 typedef _Tp& type;
00405 };
00406
00407 template<typename _Res, typename _Class>
00408 class _Mem_fn<_Res _Class::*>
00409 {
00410
00411
00412 template<typename _Tp>
00413 _Res&
00414 _M_call(_Tp& __object, _Class *) const
00415 { return __object.*__pm; }
00416
00417 template<typename _Tp, typename _Up>
00418 _Res&
00419 _M_call(_Tp& __object, _Up * const *) const
00420 { return (*__object).*__pm; }
00421
00422 template<typename _Tp, typename _Up>
00423 const _Res&
00424 _M_call(_Tp& __object, const _Up * const *) const
00425 { return (*__object).*__pm; }
00426
00427 template<typename _Tp>
00428 const _Res&
00429 _M_call(_Tp& __object, const _Class *) const
00430 { return __object.*__pm; }
00431
00432 template<typename _Tp>
00433 const _Res&
00434 _M_call(_Tp& __ptr, const volatile void*) const
00435 { return (*__ptr).*__pm; }
00436
00437 template<typename _Tp> static _Tp& __get_ref();
00438
00439 template<typename _Tp>
00440 static __sfinae_types::__one __check_const(_Tp&, _Class*);
00441 template<typename _Tp, typename _Up>
00442 static __sfinae_types::__one __check_const(_Tp&, _Up * const *);
00443 template<typename _Tp, typename _Up>
00444 static __sfinae_types::__two __check_const(_Tp&, const _Up * const *);
00445 template<typename _Tp>
00446 static __sfinae_types::__two __check_const(_Tp&, const _Class*);
00447 template<typename _Tp>
00448 static __sfinae_types::__two __check_const(_Tp&, const volatile void*);
00449
00450 public:
00451 template<typename _Tp>
00452 struct _Result_type
00453 : _Mem_fn_const_or_non<
00454 _Res,
00455 (sizeof(__sfinae_types::__two)
00456 == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))>
00457 { };
00458
00459 template<typename _Signature>
00460 struct result;
00461
00462 template<typename _CVMem, typename _Tp>
00463 struct result<_CVMem(_Tp)>
00464 : public _Result_type<_Tp> { };
00465
00466 template<typename _CVMem, typename _Tp>
00467 struct result<_CVMem(_Tp&)>
00468 : public _Result_type<_Tp> { };
00469
00470 explicit _Mem_fn(_Res _Class::*__pm) : __pm(__pm) { }
00471
00472
00473 _Res& operator()(_Class& __object) const
00474 { return __object.*__pm; }
00475
00476 const _Res& operator()(const _Class& __object) const
00477 { return __object.*__pm; }
00478
00479
00480 _Res& operator()(_Class* __object) const
00481 { return __object->*__pm; }
00482
00483 const _Res&
00484 operator()(const _Class* __object) const
00485 { return __object->*__pm; }
00486
00487
00488 template<typename _Tp>
00489 typename _Result_type<_Tp>::type
00490 operator()(_Tp& __unknown) const
00491 { return _M_call(__unknown, &__unknown); }
00492
00493 private:
00494 _Res _Class::*__pm;
00495 };
00496
00497
00498
00499
00500
00501 template<typename _Tp, typename _Class>
00502 inline _Mem_fn<_Tp _Class::*>
00503 mem_fn(_Tp _Class::* __pm)
00504 {
00505 return _Mem_fn<_Tp _Class::*>(__pm);
00506 }
00507
00508
00509
00510
00511
00512
00513 template<typename _Tp>
00514 struct is_bind_expression
00515 { static const bool value = false; };
00516
00517 template<typename _Tp>
00518 const bool is_bind_expression<_Tp>::value;
00519
00520
00521
00522
00523
00524 template<typename _Tp>
00525 struct is_placeholder
00526 { static const int value = 0; };
00527
00528 template<typename _Tp>
00529 const int is_placeholder<_Tp>::value;
00530
00531
00532
00533
00534
00535
00536 template<int _Num> struct _Placeholder { };
00537
00538
00539
00540
00541
00542
00543
00544 template<int _Num>
00545 struct is_placeholder<_Placeholder<_Num> >
00546 { static const int value = _Num; };
00547
00548 template<int _Num>
00549 const int is_placeholder<_Placeholder<_Num> >::value;
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564 template<typename _Arg,
00565 bool _IsBindExp = is_bind_expression<_Arg>::value,
00566 bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
00567 class _Mu;
00568
00569
00570
00571
00572
00573
00574
00575 template<typename _Tp>
00576 class _Mu<reference_wrapper<_Tp>, false, false>
00577 {
00578 public:
00579 typedef _Tp& result_type;
00580
00581
00582
00583
00584
00585 template<typename _CVRef, typename _Tuple>
00586 result_type
00587 operator()(_CVRef& __arg, const _Tuple&) const volatile
00588 { return __arg.get(); }
00589 };
00590
00591
00592
00593
00594
00595
00596
00597
00598 template<typename _Arg>
00599 class _Mu<_Arg, true, false>
00600 {
00601 public:
00602 template<typename _Signature> class result;
00603
00604 #define _GLIBCXX_REPEAT_HEADER <tr1/mu_iterate.h>
00605 # include <tr1/repeat.h>
00606 #undef _GLIBCXX_REPEAT_HEADER
00607 };
00608
00609
00610
00611
00612
00613
00614
00615
00616 template<typename _Arg>
00617 class _Mu<_Arg, false, true>
00618 {
00619 public:
00620 template<typename _Signature> class result;
00621
00622 template<typename _CVMu, typename _CVArg, typename _Tuple>
00623 class result<_CVMu(_CVArg, _Tuple)>
00624 {
00625
00626
00627
00628 typedef typename tuple_element<(is_placeholder<_Arg>::value - 1),
00629 _Tuple>::type __base_type;
00630
00631 public:
00632 typedef typename add_reference<__base_type>::type type;
00633 };
00634
00635 template<typename _Tuple>
00636 typename result<_Mu(_Arg, _Tuple)>::type
00637 operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile
00638 {
00639 return ::std::tr1::get<(is_placeholder<_Arg>::value - 1)>(__tuple);
00640 }
00641 };
00642
00643
00644
00645
00646
00647
00648
00649
00650 template<typename _Arg>
00651 class _Mu<_Arg, false, false>
00652 {
00653 public:
00654 template<typename _Signature> struct result;
00655
00656 template<typename _CVMu, typename _CVArg, typename _Tuple>
00657 struct result<_CVMu(_CVArg, _Tuple)>
00658 {
00659 typedef typename add_reference<_CVArg>::type type;
00660 };
00661
00662
00663 template<typename _CVArg, typename _Tuple>
00664 _CVArg& operator()(_CVArg& __arg, const _Tuple&) const volatile
00665 { return __arg; }
00666 };
00667
00668
00669
00670
00671
00672
00673
00674
00675 template<typename _Tp>
00676 struct _Maybe_wrap_member_pointer
00677 {
00678 typedef _Tp type;
00679 static const _Tp& __do_wrap(const _Tp& __x) { return __x; }
00680 };
00681
00682
00683
00684
00685
00686
00687
00688
00689 template<typename _Tp, typename _Class>
00690 struct _Maybe_wrap_member_pointer<_Tp _Class::*>
00691 {
00692 typedef _Mem_fn<_Tp _Class::*> type;
00693 static type __do_wrap(_Tp _Class::* __pm) { return type(__pm); }
00694 };
00695
00696
00697
00698
00699
00700
00701 template<typename _Signature>
00702 struct _Bind;
00703
00704
00705
00706
00707
00708
00709 template<typename _Result, typename _Signature>
00710 struct _Bind_result;
00711
00712
00713
00714
00715
00716
00717 template<typename _Signature>
00718 struct is_bind_expression<_Bind<_Signature> >
00719 { static const bool value = true; };
00720
00721 template<typename _Signature>
00722 const bool is_bind_expression<_Bind<_Signature> >::value;
00723
00724
00725
00726
00727
00728
00729 template<typename _Result, typename _Signature>
00730 struct is_bind_expression<_Bind_result<_Result, _Signature> >
00731 { static const bool value = true; };
00732
00733 template<typename _Result, typename _Signature>
00734 const bool is_bind_expression<_Bind_result<_Result, _Signature> >::value;
00735
00736
00737
00738
00739
00740
00741 class bad_function_call : public std::exception { };
00742
00743
00744
00745
00746
00747
00748
00749
00750 struct _M_clear_type;
00751
00752
00753
00754
00755
00756
00757
00758
00759 template<typename _Tp>
00760 struct __is_location_invariant
00761 : integral_constant<bool,
00762 (is_pointer<_Tp>::value
00763 || is_member_pointer<_Tp>::value)>
00764 {
00765 };
00766
00767 class _Undefined_class;
00768
00769 union _Nocopy_types
00770 {
00771 void* _M_object;
00772 const void* _M_const_object;
00773 void (*_M_function_pointer)();
00774 void (_Undefined_class::*_M_member_pointer)();
00775 };
00776
00777 union _Any_data {
00778 void* _M_access() { return &_M_pod_data[0]; }
00779 const void* _M_access() const { return &_M_pod_data[0]; }
00780
00781 template<typename _Tp> _Tp& _M_access()
00782 { return *static_cast<_Tp*>(_M_access()); }
00783
00784 template<typename _Tp> const _Tp& _M_access() const
00785 { return *static_cast<const _Tp*>(_M_access()); }
00786
00787 _Nocopy_types _M_unused;
00788 char _M_pod_data[sizeof(_Nocopy_types)];
00789 };
00790
00791 enum _Manager_operation
00792 {
00793 __get_type_info,
00794 __get_functor_ptr,
00795 __clone_functor,
00796 __destroy_functor
00797 };
00798
00799
00800
00801 template<typename _Tp>
00802 struct _Simple_type_wrapper
00803 {
00804 _Simple_type_wrapper(_Tp __value) : __value(__value) { }
00805
00806 _Tp __value;
00807 };
00808
00809 template<typename _Tp>
00810 struct __is_location_invariant<_Simple_type_wrapper<_Tp> >
00811 : __is_location_invariant<_Tp>
00812 {
00813 };
00814
00815
00816
00817 template<typename _Functor>
00818 inline _Functor& __callable_functor(_Functor& __f) { return __f; }
00819
00820 template<typename _Member, typename _Class>
00821 inline _Mem_fn<_Member _Class::*>
00822 __callable_functor(_Member _Class::* &__p)
00823 { return mem_fn(__p); }
00824
00825 template<typename _Member, typename _Class>
00826 inline _Mem_fn<_Member _Class::*>
00827 __callable_functor(_Member _Class::* const &__p)
00828 { return mem_fn(__p); }
00829
00830 template<typename _Signature, typename _Functor>
00831 class _Function_handler;
00832
00833 template<typename _Signature>
00834 class function;
00835
00836
00837
00838
00839
00840
00841
00842 class _Function_base
00843 {
00844 public:
00845 static const std::size_t _M_max_size = sizeof(_Nocopy_types);
00846 static const std::size_t _M_max_align = __alignof__(_Nocopy_types);
00847
00848 template<typename _Functor>
00849 class _Base_manager
00850 {
00851 protected:
00852 static const bool __stored_locally =
00853 (__is_location_invariant<_Functor>::value
00854 && sizeof(_Functor) <= _M_max_size
00855 && __alignof__(_Functor) <= _M_max_align
00856 && (_M_max_align % __alignof__(_Functor) == 0));
00857 typedef integral_constant<bool, __stored_locally> _Local_storage;
00858
00859
00860 static _Functor* _M_get_pointer(const _Any_data& __source)
00861 {
00862 const _Functor* __ptr =
00863 __stored_locally? &__source._M_access<_Functor>()
00864 : __source._M_access<_Functor*>();
00865 return const_cast<_Functor*>(__ptr);
00866 }
00867
00868
00869
00870 static void
00871 _M_clone(_Any_data& __dest, const _Any_data& __source, true_type)
00872 {
00873 new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
00874 }
00875
00876
00877
00878 static void
00879 _M_clone(_Any_data& __dest, const _Any_data& __source, false_type)
00880 {
00881 __dest._M_access<_Functor*>() =
00882 new _Functor(*__source._M_access<_Functor*>());
00883 }
00884
00885
00886
00887 static void
00888 _M_destroy(_Any_data& __victim, true_type)
00889 {
00890 __victim._M_access<_Functor>().~_Functor();
00891 }
00892
00893
00894 static void
00895 _M_destroy(_Any_data& __victim, false_type)
00896 {
00897 delete __victim._M_access<_Functor*>();
00898 }
00899
00900 public:
00901 static bool
00902 _M_manager(_Any_data& __dest, const _Any_data& __source,
00903 _Manager_operation __op)
00904 {
00905 switch (__op) {
00906 case __get_type_info:
00907 __dest._M_access<const type_info*>() = &typeid(_Functor);
00908 break;
00909
00910 case __get_functor_ptr:
00911 __dest._M_access<_Functor*>() = _M_get_pointer(__source);
00912 break;
00913
00914 case __clone_functor:
00915 _M_clone(__dest, __source, _Local_storage());
00916 break;
00917
00918 case __destroy_functor:
00919 _M_destroy(__dest, _Local_storage());
00920 break;
00921 }
00922 return false;
00923 }
00924
00925 static void
00926 _M_init_functor(_Any_data& __functor, const _Functor& __f)
00927 {
00928 _M_init_functor(__functor, __f, _Local_storage());
00929 }
00930
00931 template<typename _Signature>
00932 static bool
00933 _M_not_empty_function(const function<_Signature>& __f)
00934 {
00935 return __f;
00936 }
00937
00938 template<typename _Tp>
00939 static bool
00940 _M_not_empty_function(const _Tp*& __fp)
00941 {
00942 return __fp;
00943 }
00944
00945 template<typename _Class, typename _Tp>
00946 static bool
00947 _M_not_empty_function(_Tp _Class::* const& __mp)
00948 {
00949 return __mp;
00950 }
00951
00952 template<typename _Tp>
00953 static bool
00954 _M_not_empty_function(const _Tp&)
00955 {
00956 return true;
00957 }
00958
00959 private:
00960 static void
00961 _M_init_functor(_Any_data& __functor, const _Functor& __f, true_type)
00962 {
00963 new (__functor._M_access()) _Functor(__f);
00964 }
00965
00966 static void
00967 _M_init_functor(_Any_data& __functor, const _Functor& __f, false_type)
00968 {
00969 __functor._M_access<_Functor*>() = new _Functor(__f);
00970 }
00971 };
00972
00973 template<typename _Functor>
00974 class _Ref_manager : public _Base_manager<_Functor*>
00975 {
00976 typedef _Function_base::_Base_manager<_Functor*> _Base;
00977
00978 public:
00979 static bool
00980 _M_manager(_Any_data& __dest, const _Any_data& __source,
00981 _Manager_operation __op)
00982 {
00983 switch (__op) {
00984 case __get_type_info:
00985 __dest._M_access<const type_info*>() = &typeid(_Functor);
00986 break;
00987
00988 case __get_functor_ptr:
00989 __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source);
00990 return is_const<_Functor>::value;
00991 break;
00992
00993 default:
00994 _Base::_M_manager(__dest, __source, __op);
00995 }
00996 return false;
00997 }
00998
00999 static void
01000 _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f)
01001 {
01002
01003 _Base::_M_init_functor(__functor, &__f.get());
01004 }
01005 };
01006
01007 _Function_base() : _M_manager(0) { }
01008
01009 ~_Function_base()
01010 {
01011 if (_M_manager)
01012 {
01013 _M_manager(_M_functor, _M_functor, __destroy_functor);
01014 }
01015 }
01016
01017
01018 bool _M_empty() const { return !_M_manager; }
01019
01020 typedef bool (*_Manager_type)(_Any_data&, const _Any_data&,
01021 _Manager_operation);
01022
01023 _Any_data _M_functor;
01024 _Manager_type _M_manager;
01025 };
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036 template<typename _Signature>
01037 inline bool
01038 operator==(const function<_Signature>& __f, _M_clear_type*)
01039 {
01040 return !__f;
01041 }
01042
01043
01044
01045
01046 template<typename _Signature>
01047 inline bool
01048 operator==(_M_clear_type*, const function<_Signature>& __f)
01049 {
01050 return !__f;
01051 }
01052
01053
01054
01055
01056
01057
01058
01059
01060 template<typename _Signature>
01061 inline bool
01062 operator!=(const function<_Signature>& __f, _M_clear_type*)
01063 {
01064 return __f;
01065 }
01066
01067
01068
01069
01070 template<typename _Signature>
01071 inline bool
01072 operator!=(_M_clear_type*, const function<_Signature>& __f)
01073 {
01074 return __f;
01075 }
01076
01077
01078
01079
01080
01081
01082
01083
01084 template<typename _Signature>
01085 inline void
01086 swap(function<_Signature>& __x, function<_Signature>& __y)
01087 {
01088 __x.swap(__y);
01089 }
01090
01091 _GLIBCXX_END_NAMESPACE
01092 }
01093
01094 #define _GLIBCXX_JOIN(X,Y) _GLIBCXX_JOIN2( X , Y )
01095 #define _GLIBCXX_JOIN2(X,Y) _GLIBCXX_JOIN3(X,Y)
01096 #define _GLIBCXX_JOIN3(X,Y) X##Y
01097 #define _GLIBCXX_REPEAT_HEADER <tr1/functional_iterate.h>
01098 #include <tr1/repeat.h>
01099 #undef _GLIBCXX_REPEAT_HEADER
01100 #undef _GLIBCXX_JOIN3
01101 #undef _GLIBCXX_JOIN2
01102 #undef _GLIBCXX_JOIN
01103
01104 #include <tr1/functional_hash.h>
01105
01106 #endif