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