tr1_impl/functional

Go to the documentation of this file.
00001 // TR1 functional header -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file tr1_impl/functional
00026  *  This is an internal header file, included by other library headers.
00027  *  You should not attempt to use it directly.
00028  */
00029 
00030 namespace std
00031 {
00032 _GLIBCXX_BEGIN_NAMESPACE_TR1
00033 
00034   template<typename _MemberPointer>
00035     class _Mem_fn;
00036 
00037   /**
00038    *  Actual implementation of _Has_result_type, which uses SFINAE to
00039    *  determine if the type _Tp has a publicly-accessible member type
00040    *  result_type.
00041   */
00042   template<typename _Tp>
00043     class _Has_result_type_helper : __sfinae_types
00044     {
00045       template<typename _Up>
00046         struct _Wrap_type
00047     { };
00048 
00049       template<typename _Up>
00050         static __one __test(_Wrap_type<typename _Up::result_type>*);
00051 
00052       template<typename _Up>
00053         static __two __test(...);
00054 
00055     public:
00056       static const bool value = sizeof(__test<_Tp>(0)) == 1;
00057     };
00058 
00059   template<typename _Tp>
00060     struct _Has_result_type
00061     : integral_constant<bool,
00062           _Has_result_type_helper<typename remove_cv<_Tp>::type>::value>
00063     { };
00064 
00065   /**
00066    *  
00067   */
00068   /// If we have found a result_type, extract it.
00069   template<bool _Has_result_type, typename _Functor>
00070     struct _Maybe_get_result_type
00071     { };
00072 
00073   template<typename _Functor>
00074     struct _Maybe_get_result_type<true, _Functor>
00075     {
00076       typedef typename _Functor::result_type result_type;
00077     };
00078 
00079   /**
00080    *  Base class for any function object that has a weak result type, as
00081    *  defined in 3.3/3 of TR1.
00082   */
00083   template<typename _Functor>
00084     struct _Weak_result_type_impl
00085     : _Maybe_get_result_type<_Has_result_type<_Functor>::value, _Functor>
00086     {
00087     };
00088 
00089   /// Retrieve the result type for a function type.
00090   template<typename _Res, typename... _ArgTypes> 
00091     struct _Weak_result_type_impl<_Res(_ArgTypes...)>
00092     {
00093       typedef _Res result_type;
00094     };
00095 
00096   /// Retrieve the result type for a function reference.
00097   template<typename _Res, typename... _ArgTypes> 
00098     struct _Weak_result_type_impl<_Res(&)(_ArgTypes...)>
00099     {
00100       typedef _Res result_type;
00101     };
00102 
00103   /// Retrieve the result type for a function pointer.
00104   template<typename _Res, typename... _ArgTypes> 
00105     struct _Weak_result_type_impl<_Res(*)(_ArgTypes...)>
00106     {
00107       typedef _Res result_type;
00108     };
00109 
00110   /// Retrieve result type for a member function pointer. 
00111   template<typename _Res, typename _Class, typename... _ArgTypes> 
00112     struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)>
00113     {
00114       typedef _Res result_type;
00115     };
00116 
00117   /// Retrieve result type for a const member function pointer. 
00118   template<typename _Res, typename _Class, typename... _ArgTypes> 
00119     struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) const>
00120     {
00121       typedef _Res result_type;
00122     };
00123 
00124   /// Retrieve result type for a volatile member function pointer. 
00125   template<typename _Res, typename _Class, typename... _ArgTypes> 
00126     struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...) volatile>
00127     {
00128       typedef _Res result_type;
00129     };
00130 
00131   /// Retrieve result type for a const volatile member function pointer. 
00132   template<typename _Res, typename _Class, typename... _ArgTypes> 
00133     struct _Weak_result_type_impl<_Res (_Class::*)(_ArgTypes...)const volatile>
00134     {
00135       typedef _Res result_type;
00136     };
00137 
00138   /**
00139    *  Strip top-level cv-qualifiers from the function object and let
00140    *  _Weak_result_type_impl perform the real work.
00141   */
00142   template<typename _Functor>
00143     struct _Weak_result_type
00144     : _Weak_result_type_impl<typename remove_cv<_Functor>::type>
00145     {
00146     };
00147 
00148   template<typename _Signature>
00149     class result_of;
00150 
00151   /**
00152    *  Actual implementation of result_of. When _Has_result_type is
00153    *  true, gets its result from _Weak_result_type. Otherwise, uses
00154    *  the function object's member template result to extract the
00155    *  result type.
00156   */
00157   template<bool _Has_result_type, typename _Signature>
00158     struct _Result_of_impl;
00159 
00160   // Handle member data pointers using _Mem_fn's logic
00161   template<typename _Res, typename _Class, typename _T1>
00162     struct _Result_of_impl<false, _Res _Class::*(_T1)>
00163     {
00164       typedef typename _Mem_fn<_Res _Class::*>
00165                 ::template _Result_type<_T1>::type type;
00166     };
00167 
00168   /**
00169    * Determine whether we can determine a result type from @c Functor 
00170    * alone.
00171    */ 
00172   template<typename _Functor, typename... _ArgTypes>
00173     class result_of<_Functor(_ArgTypes...)>
00174     : public _Result_of_impl<
00175                _Has_result_type<_Weak_result_type<_Functor> >::value,
00176                _Functor(_ArgTypes...)>
00177     {
00178     };
00179 
00180   /// We already know the result type for @c Functor; use it.
00181   template<typename _Functor, typename... _ArgTypes>
00182     struct _Result_of_impl<true, _Functor(_ArgTypes...)>
00183     {
00184       typedef typename _Weak_result_type<_Functor>::result_type type;
00185     };
00186 
00187   /**
00188    * We need to compute the result type for this invocation the hard 
00189    * way.
00190    */
00191   template<typename _Functor, typename... _ArgTypes>
00192     struct _Result_of_impl<false, _Functor(_ArgTypes...)>
00193     {
00194       typedef typename _Functor
00195                 ::template result<_Functor(_ArgTypes...)>::type type;
00196     };
00197 
00198   /**
00199    * It is unsafe to access ::result when there are zero arguments, so we 
00200    * return @c void instead.
00201    */
00202   template<typename _Functor>
00203     struct _Result_of_impl<false, _Functor()>
00204     {
00205       typedef void type;
00206     };
00207 
00208   /// Determines if the type _Tp derives from unary_function.
00209   template<typename _Tp>
00210     struct _Derives_from_unary_function : __sfinae_types
00211     {
00212     private:
00213       template<typename _T1, typename _Res>
00214         static __one __test(const volatile unary_function<_T1, _Res>*);
00215 
00216       // It's tempting to change "..." to const volatile void*, but
00217       // that fails when _Tp is a function type.
00218       static __two __test(...);
00219 
00220     public:
00221       static const bool value = sizeof(__test((_Tp*)0)) == 1;
00222     };
00223 
00224   /// Determines if the type _Tp derives from binary_function.
00225   template<typename _Tp>
00226     struct _Derives_from_binary_function : __sfinae_types
00227     {
00228     private:
00229       template<typename _T1, typename _T2, typename _Res>
00230         static __one __test(const volatile binary_function<_T1, _T2, _Res>*);
00231 
00232       // It's tempting to change "..." to const volatile void*, but
00233       // that fails when _Tp is a function type.
00234       static __two __test(...);
00235 
00236     public:
00237       static const bool value = sizeof(__test((_Tp*)0)) == 1;
00238     };
00239 
00240   /// Turns a function type into a function pointer type
00241   template<typename _Tp, bool _IsFunctionType = is_function<_Tp>::value>
00242     struct _Function_to_function_pointer
00243     {
00244       typedef _Tp type;
00245     };
00246 
00247   template<typename _Tp>
00248     struct _Function_to_function_pointer<_Tp, true>
00249     {
00250       typedef _Tp* type;
00251     };
00252 
00253   /**
00254    * Invoke a function object, which may be either a member pointer or a
00255    * function object. The first parameter will tell which.
00256    */
00257   template<typename _Functor, typename... _Args>
00258     inline
00259     typename __gnu_cxx::__enable_if<
00260              (!is_member_pointer<_Functor>::value
00261               && !is_function<_Functor>::value
00262               && !is_function<typename remove_pointer<_Functor>::type>::value),
00263              typename result_of<_Functor(_Args...)>::type
00264            >::__type
00265     __invoke(_Functor& __f, _Args&... __args)
00266     {
00267       return __f(__args...);
00268     }
00269 
00270   template<typename _Functor, typename... _Args>
00271     inline
00272     typename __gnu_cxx::__enable_if<
00273              (is_member_pointer<_Functor>::value
00274               && !is_function<_Functor>::value
00275               && !is_function<typename remove_pointer<_Functor>::type>::value),
00276              typename result_of<_Functor(_Args...)>::type
00277            >::__type
00278     __invoke(_Functor& __f, _Args&... __args)
00279     {
00280       return mem_fn(__f)(__args...);
00281     }
00282 
00283   // To pick up function references (that will become function pointers)
00284   template<typename _Functor, typename... _Args>
00285     inline
00286     typename __gnu_cxx::__enable_if<
00287              (is_pointer<_Functor>::value
00288               && is_function<typename remove_pointer<_Functor>::type>::value),
00289              typename result_of<_Functor(_Args...)>::type
00290            >::__type
00291     __invoke(_Functor __f, _Args&... __args)
00292     {
00293       return __f(__args...);
00294     }
00295 
00296   /**
00297    *  Knowing which of unary_function and binary_function _Tp derives
00298    *  from, derives from the same and ensures that reference_wrapper
00299    *  will have a weak result type. See cases below.
00300    */
00301   template<bool _Unary, bool _Binary, typename _Tp>
00302     struct _Reference_wrapper_base_impl;
00303 
00304   // Not a unary_function or binary_function, so try a weak result type.
00305   template<typename _Tp>
00306     struct _Reference_wrapper_base_impl<false, false, _Tp>
00307     : _Weak_result_type<_Tp>
00308     { };
00309 
00310   // unary_function but not binary_function
00311   template<typename _Tp>
00312     struct _Reference_wrapper_base_impl<true, false, _Tp>
00313     : unary_function<typename _Tp::argument_type,
00314              typename _Tp::result_type>
00315     { };
00316 
00317   // binary_function but not unary_function
00318   template<typename _Tp>
00319     struct _Reference_wrapper_base_impl<false, true, _Tp>
00320     : binary_function<typename _Tp::first_argument_type,
00321               typename _Tp::second_argument_type,
00322               typename _Tp::result_type>
00323     { };
00324 
00325   // Both unary_function and binary_function. Import result_type to
00326   // avoid conflicts.
00327    template<typename _Tp>
00328     struct _Reference_wrapper_base_impl<true, true, _Tp>
00329     : unary_function<typename _Tp::argument_type,
00330              typename _Tp::result_type>,
00331       binary_function<typename _Tp::first_argument_type,
00332               typename _Tp::second_argument_type,
00333               typename _Tp::result_type>
00334     {
00335       typedef typename _Tp::result_type result_type;
00336     };
00337 
00338   /**
00339    *  Derives from unary_function or binary_function when it
00340    *  can. Specializations handle all of the easy cases. The primary
00341    *  template determines what to do with a class type, which may
00342    *  derive from both unary_function and binary_function.
00343   */
00344   template<typename _Tp>
00345     struct _Reference_wrapper_base
00346     : _Reference_wrapper_base_impl<
00347       _Derives_from_unary_function<_Tp>::value,
00348       _Derives_from_binary_function<_Tp>::value,
00349       _Tp>
00350     { };
00351 
00352   // - a function type (unary)
00353   template<typename _Res, typename _T1>
00354     struct _Reference_wrapper_base<_Res(_T1)>
00355     : unary_function<_T1, _Res>
00356     { };
00357 
00358   // - a function type (binary)
00359   template<typename _Res, typename _T1, typename _T2>
00360     struct _Reference_wrapper_base<_Res(_T1, _T2)>
00361     : binary_function<_T1, _T2, _Res>
00362     { };
00363 
00364   // - a function pointer type (unary)
00365   template<typename _Res, typename _T1>
00366     struct _Reference_wrapper_base<_Res(*)(_T1)>
00367     : unary_function<_T1, _Res>
00368     { };
00369 
00370   // - a function pointer type (binary)
00371   template<typename _Res, typename _T1, typename _T2>
00372     struct _Reference_wrapper_base<_Res(*)(_T1, _T2)>
00373     : binary_function<_T1, _T2, _Res>
00374     { };
00375 
00376   // - a pointer to member function type (unary, no qualifiers)
00377   template<typename _Res, typename _T1>
00378     struct _Reference_wrapper_base<_Res (_T1::*)()>
00379     : unary_function<_T1*, _Res>
00380     { };
00381 
00382   // - a pointer to member function type (binary, no qualifiers)
00383   template<typename _Res, typename _T1, typename _T2>
00384     struct _Reference_wrapper_base<_Res (_T1::*)(_T2)>
00385     : binary_function<_T1*, _T2, _Res>
00386     { };
00387 
00388   // - a pointer to member function type (unary, const)
00389   template<typename _Res, typename _T1>
00390     struct _Reference_wrapper_base<_Res (_T1::*)() const>
00391     : unary_function<const _T1*, _Res>
00392     { };
00393 
00394   // - a pointer to member function type (binary, const)
00395   template<typename _Res, typename _T1, typename _T2>
00396     struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const>
00397     : binary_function<const _T1*, _T2, _Res>
00398     { };
00399 
00400   // - a pointer to member function type (unary, volatile)
00401   template<typename _Res, typename _T1>
00402     struct _Reference_wrapper_base<_Res (_T1::*)() volatile>
00403     : unary_function<volatile _T1*, _Res>
00404     { };
00405 
00406   // - a pointer to member function type (binary, volatile)
00407   template<typename _Res, typename _T1, typename _T2>
00408     struct _Reference_wrapper_base<_Res (_T1::*)(_T2) volatile>
00409     : binary_function<volatile _T1*, _T2, _Res>
00410     { };
00411 
00412   // - a pointer to member function type (unary, const volatile)
00413   template<typename _Res, typename _T1>
00414     struct _Reference_wrapper_base<_Res (_T1::*)() const volatile>
00415     : unary_function<const volatile _T1*, _Res>
00416     { };
00417 
00418   // - a pointer to member function type (binary, const volatile)
00419   template<typename _Res, typename _T1, typename _T2>
00420     struct _Reference_wrapper_base<_Res (_T1::*)(_T2) const volatile>
00421     : binary_function<const volatile _T1*, _T2, _Res>
00422     { };
00423 
00424   /// reference_wrapper
00425   template<typename _Tp>
00426     class reference_wrapper
00427     : public _Reference_wrapper_base<typename remove_cv<_Tp>::type>
00428     {
00429       // If _Tp is a function type, we can't form result_of<_Tp(...)>,
00430       // so turn it into a function pointer type.
00431       typedef typename _Function_to_function_pointer<_Tp>::type
00432         _M_func_type;
00433 
00434       _Tp* _M_data;
00435     public:
00436       typedef _Tp type;
00437 
00438       explicit
00439       reference_wrapper(_Tp& __indata): _M_data(&__indata)
00440       { }
00441 
00442       reference_wrapper(const reference_wrapper<_Tp>& __inref):
00443       _M_data(__inref._M_data)
00444       { }
00445 
00446       reference_wrapper&
00447       operator=(const reference_wrapper<_Tp>& __inref)
00448       {
00449         _M_data = __inref._M_data;
00450         return *this;
00451       }
00452 
00453       operator _Tp&() const
00454       { return this->get(); }
00455 
00456       _Tp&
00457       get() const
00458       { return *_M_data; }
00459 
00460       template<typename... _Args>
00461         typename result_of<_M_func_type(_Args...)>::type
00462         operator()(_Args&... __args) const
00463         {
00464       return __invoke(get(), __args...);
00465     }
00466     };
00467 
00468 
00469   // Denotes a reference should be taken to a variable.
00470   template<typename _Tp>
00471     inline reference_wrapper<_Tp>
00472     ref(_Tp& __t)
00473     { return reference_wrapper<_Tp>(__t); }
00474 
00475   // Denotes a const reference should be taken to a variable.
00476   template<typename _Tp>
00477     inline reference_wrapper<const _Tp>
00478     cref(const _Tp& __t)
00479     { return reference_wrapper<const _Tp>(__t); }
00480 
00481   template<typename _Tp>
00482     inline reference_wrapper<_Tp>
00483     ref(reference_wrapper<_Tp> __t)
00484     { return ref(__t.get()); }
00485 
00486   template<typename _Tp>
00487     inline reference_wrapper<const _Tp>
00488     cref(reference_wrapper<_Tp> __t)
00489     { return cref(__t.get()); }
00490 
00491   template<typename _Tp, bool>
00492     struct _Mem_fn_const_or_non
00493     {
00494       typedef const _Tp& type;
00495     };
00496 
00497   template<typename _Tp>
00498     struct _Mem_fn_const_or_non<_Tp, false>
00499     {
00500       typedef _Tp& type;
00501     };
00502 
00503   /**
00504    * Derives from @c unary_function or @c binary_function, or perhaps
00505    * nothing, depending on the number of arguments provided. The
00506    * primary template is the basis case, which derives nothing.
00507    */
00508   template<typename _Res, typename... _ArgTypes> 
00509     struct _Maybe_unary_or_binary_function { };
00510 
00511   /// Derives from @c unary_function, as appropriate. 
00512   template<typename _Res, typename _T1> 
00513     struct _Maybe_unary_or_binary_function<_Res, _T1>
00514     : std::unary_function<_T1, _Res> { };
00515 
00516   /// Derives from @c binary_function, as appropriate. 
00517   template<typename _Res, typename _T1, typename _T2> 
00518     struct _Maybe_unary_or_binary_function<_Res, _T1, _T2>
00519     : std::binary_function<_T1, _T2, _Res> { };
00520 
00521   /// Implementation of @c mem_fn for member function pointers.
00522   template<typename _Res, typename _Class, typename... _ArgTypes>
00523     class _Mem_fn<_Res (_Class::*)(_ArgTypes...)>
00524     : public _Maybe_unary_or_binary_function<_Res, _Class*, _ArgTypes...>
00525     {
00526       typedef _Res (_Class::*_Functor)(_ArgTypes...);
00527 
00528       template<typename _Tp>
00529         _Res
00530         _M_call(_Tp& __object, const volatile _Class *, 
00531                 _ArgTypes... __args) const
00532         { return (__object.*__pmf)(__args...); }
00533 
00534       template<typename _Tp>
00535         _Res
00536         _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
00537         { return ((*__ptr).*__pmf)(__args...); }
00538 
00539     public:
00540       typedef _Res result_type;
00541 
00542       explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
00543 
00544       // Handle objects
00545       _Res
00546       operator()(_Class& __object, _ArgTypes... __args) const
00547       { return (__object.*__pmf)(__args...); }
00548 
00549       // Handle pointers
00550       _Res
00551       operator()(_Class* __object, _ArgTypes... __args) const
00552       { return (__object->*__pmf)(__args...); }
00553 
00554       // Handle smart pointers, references and pointers to derived
00555       template<typename _Tp>
00556         _Res
00557     operator()(_Tp& __object, _ArgTypes... __args) const
00558         { return _M_call(__object, &__object, __args...); }
00559 
00560     private:
00561       _Functor __pmf;
00562     };
00563 
00564   /// Implementation of @c mem_fn for const member function pointers.
00565   template<typename _Res, typename _Class, typename... _ArgTypes>
00566     class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const>
00567     : public _Maybe_unary_or_binary_function<_Res, const _Class*, 
00568                          _ArgTypes...>
00569     {
00570       typedef _Res (_Class::*_Functor)(_ArgTypes...) const;
00571 
00572       template<typename _Tp>
00573         _Res
00574         _M_call(_Tp& __object, const volatile _Class *, 
00575                 _ArgTypes... __args) const
00576         { return (__object.*__pmf)(__args...); }
00577 
00578       template<typename _Tp>
00579         _Res
00580         _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
00581         { return ((*__ptr).*__pmf)(__args...); }
00582 
00583     public:
00584       typedef _Res result_type;
00585 
00586       explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
00587 
00588       // Handle objects
00589       _Res
00590       operator()(const _Class& __object, _ArgTypes... __args) const
00591       { return (__object.*__pmf)(__args...); }
00592 
00593       // Handle pointers
00594       _Res
00595       operator()(const _Class* __object, _ArgTypes... __args) const
00596       { return (__object->*__pmf)(__args...); }
00597 
00598       // Handle smart pointers, references and pointers to derived
00599       template<typename _Tp>
00600         _Res operator()(_Tp& __object, _ArgTypes... __args) const
00601         { return _M_call(__object, &__object, __args...); }
00602 
00603     private:
00604       _Functor __pmf;
00605     };
00606 
00607   /// Implementation of @c mem_fn for volatile member function pointers.
00608   template<typename _Res, typename _Class, typename... _ArgTypes>
00609     class _Mem_fn<_Res (_Class::*)(_ArgTypes...) volatile>
00610     : public _Maybe_unary_or_binary_function<_Res, volatile _Class*, 
00611                          _ArgTypes...>
00612     {
00613       typedef _Res (_Class::*_Functor)(_ArgTypes...) volatile;
00614 
00615       template<typename _Tp>
00616         _Res
00617         _M_call(_Tp& __object, const volatile _Class *, 
00618                 _ArgTypes... __args) const
00619         { return (__object.*__pmf)(__args...); }
00620 
00621       template<typename _Tp>
00622         _Res
00623         _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
00624         { return ((*__ptr).*__pmf)(__args...); }
00625 
00626     public:
00627       typedef _Res result_type;
00628 
00629       explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
00630 
00631       // Handle objects
00632       _Res
00633       operator()(volatile _Class& __object, _ArgTypes... __args) const
00634       { return (__object.*__pmf)(__args...); }
00635 
00636       // Handle pointers
00637       _Res
00638       operator()(volatile _Class* __object, _ArgTypes... __args) const
00639       { return (__object->*__pmf)(__args...); }
00640 
00641       // Handle smart pointers, references and pointers to derived
00642       template<typename _Tp>
00643         _Res
00644     operator()(_Tp& __object, _ArgTypes... __args) const
00645         { return _M_call(__object, &__object, __args...); }
00646 
00647     private:
00648       _Functor __pmf;
00649     };
00650 
00651   /// Implementation of @c mem_fn for const volatile member function pointers.
00652   template<typename _Res, typename _Class, typename... _ArgTypes>
00653     class _Mem_fn<_Res (_Class::*)(_ArgTypes...) const volatile>
00654     : public _Maybe_unary_or_binary_function<_Res, const volatile _Class*, 
00655                          _ArgTypes...>
00656     {
00657       typedef _Res (_Class::*_Functor)(_ArgTypes...) const volatile;
00658 
00659       template<typename _Tp>
00660         _Res
00661         _M_call(_Tp& __object, const volatile _Class *, 
00662                 _ArgTypes... __args) const
00663         { return (__object.*__pmf)(__args...); }
00664 
00665       template<typename _Tp>
00666         _Res
00667         _M_call(_Tp& __ptr, const volatile void *, _ArgTypes... __args) const
00668         { return ((*__ptr).*__pmf)(__args...); }
00669 
00670     public:
00671       typedef _Res result_type;
00672 
00673       explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }
00674 
00675       // Handle objects
00676       _Res 
00677       operator()(const volatile _Class& __object, _ArgTypes... __args) const
00678       { return (__object.*__pmf)(__args...); }
00679 
00680       // Handle pointers
00681       _Res 
00682       operator()(const volatile _Class* __object, _ArgTypes... __args) const
00683       { return (__object->*__pmf)(__args...); }
00684 
00685       // Handle smart pointers, references and pointers to derived
00686       template<typename _Tp>
00687         _Res operator()(_Tp& __object, _ArgTypes... __args) const
00688         { return _M_call(__object, &__object, __args...); }
00689 
00690     private:
00691       _Functor __pmf;
00692     };
00693 
00694 
00695   template<typename _Res, typename _Class>
00696     class _Mem_fn<_Res _Class::*>
00697     {
00698       // This bit of genius is due to Peter Dimov, improved slightly by
00699       // Douglas Gregor.
00700       template<typename _Tp>
00701         _Res&
00702         _M_call(_Tp& __object, _Class *) const
00703         { return __object.*__pm; }
00704 
00705       template<typename _Tp, typename _Up>
00706         _Res&
00707         _M_call(_Tp& __object, _Up * const *) const
00708         { return (*__object).*__pm; }
00709 
00710       template<typename _Tp, typename _Up>
00711         const _Res&
00712         _M_call(_Tp& __object, const _Up * const *) const
00713         { return (*__object).*__pm; }
00714 
00715       template<typename _Tp>
00716         const _Res&
00717         _M_call(_Tp& __object, const _Class *) const
00718         { return __object.*__pm; }
00719 
00720       template<typename _Tp>
00721         const _Res&
00722         _M_call(_Tp& __ptr, const volatile void*) const
00723         { return (*__ptr).*__pm; }
00724 
00725       template<typename _Tp> static _Tp& __get_ref();
00726 
00727       template<typename _Tp>
00728         static __sfinae_types::__one __check_const(_Tp&, _Class*);
00729       template<typename _Tp, typename _Up>
00730         static __sfinae_types::__one __check_const(_Tp&, _Up * const *);
00731       template<typename _Tp, typename _Up>
00732         static __sfinae_types::__two __check_const(_Tp&, const _Up * const *);
00733       template<typename _Tp>
00734         static __sfinae_types::__two __check_const(_Tp&, const _Class*);
00735       template<typename _Tp>
00736         static __sfinae_types::__two __check_const(_Tp&, const volatile void*);
00737 
00738     public:
00739       template<typename _Tp>
00740         struct _Result_type
00741     : _Mem_fn_const_or_non<_Res,
00742       (sizeof(__sfinae_types::__two)
00743        == sizeof(__check_const<_Tp>(__get_ref<_Tp>(), (_Tp*)0)))>
00744         { };
00745 
00746       template<typename _Signature>
00747         struct result;
00748 
00749       template<typename _CVMem, typename _Tp>
00750         struct result<_CVMem(_Tp)>
00751     : public _Result_type<_Tp> { };
00752 
00753       template<typename _CVMem, typename _Tp>
00754         struct result<_CVMem(_Tp&)>
00755     : public _Result_type<_Tp> { };
00756 
00757       explicit
00758       _Mem_fn(_Res _Class::*__pm) : __pm(__pm) { }
00759 
00760       // Handle objects
00761       _Res&
00762       operator()(_Class& __object) const
00763       { return __object.*__pm; }
00764 
00765       const _Res&
00766       operator()(const _Class& __object) const
00767       { return __object.*__pm; }
00768 
00769       // Handle pointers
00770       _Res&
00771       operator()(_Class* __object) const
00772       { return __object->*__pm; }
00773 
00774       const _Res&
00775       operator()(const _Class* __object) const
00776       { return __object->*__pm; }
00777 
00778       // Handle smart pointers and derived
00779       template<typename _Tp>
00780         typename _Result_type<_Tp>::type
00781         operator()(_Tp& __unknown) const
00782         { return _M_call(__unknown, &__unknown); }
00783 
00784     private:
00785       _Res _Class::*__pm;
00786     };
00787 
00788   /**
00789    *  @brief Returns a function object that forwards to the member
00790    *  pointer @a pm.
00791    */
00792   template<typename _Tp, typename _Class>
00793     inline _Mem_fn<_Tp _Class::*>
00794     mem_fn(_Tp _Class::* __pm)
00795     {
00796       return _Mem_fn<_Tp _Class::*>(__pm);
00797     }
00798 
00799   /**
00800    *  @brief Determines if the given type _Tp is a function object
00801    *  should be treated as a subexpression when evaluating calls to
00802    *  function objects returned by bind(). [TR1 3.6.1]
00803    */
00804   template<typename _Tp>
00805     struct is_bind_expression
00806     { static const bool value = false; };
00807 
00808   template<typename _Tp>
00809     const bool is_bind_expression<_Tp>::value;
00810 
00811   /**
00812    *  @brief Determines if the given type _Tp is a placeholder in a
00813    *  bind() expression and, if so, which placeholder it is. [TR1 3.6.2]
00814    */
00815   template<typename _Tp>
00816     struct is_placeholder
00817     { static const int value = 0; };
00818 
00819   template<typename _Tp>
00820     const int is_placeholder<_Tp>::value;
00821 
00822   /// The type of placeholder objects defined by libstdc++.
00823   template<int _Num> struct _Placeholder { };
00824 
00825   /** @namespace std::placeholders
00826    *  @brief ISO C++ 0x entities sub namespace for functional.
00827    *
00828    *  Define a large number of placeholders. There is no way to
00829    *  simplify this with variadic templates, because we're introducing
00830    *  unique names for each.
00831    */
00832   namespace placeholders 
00833   { 
00834     namespace 
00835     {
00836       _Placeholder<1> _1;
00837       _Placeholder<2> _2;
00838       _Placeholder<3> _3;
00839       _Placeholder<4> _4;
00840       _Placeholder<5> _5;
00841       _Placeholder<6> _6;
00842       _Placeholder<7> _7;
00843       _Placeholder<8> _8;
00844       _Placeholder<9> _9;
00845       _Placeholder<10> _10;
00846       _Placeholder<11> _11;
00847       _Placeholder<12> _12;
00848       _Placeholder<13> _13;
00849       _Placeholder<14> _14;
00850       _Placeholder<15> _15;
00851       _Placeholder<16> _16;
00852       _Placeholder<17> _17;
00853       _Placeholder<18> _18;
00854       _Placeholder<19> _19;
00855       _Placeholder<20> _20;
00856       _Placeholder<21> _21;
00857       _Placeholder<22> _22;
00858       _Placeholder<23> _23;
00859       _Placeholder<24> _24;
00860       _Placeholder<25> _25;
00861       _Placeholder<26> _26;
00862       _Placeholder<27> _27;
00863       _Placeholder<28> _28;
00864       _Placeholder<29> _29;
00865     } 
00866   }
00867 
00868   /**
00869    *  Partial specialization of is_placeholder that provides the placeholder
00870    *  number for the placeholder objects defined by libstdc++.
00871    */
00872   template<int _Num>
00873     struct is_placeholder<_Placeholder<_Num> >
00874     { static const int value = _Num; };
00875 
00876   template<int _Num>
00877     const int is_placeholder<_Placeholder<_Num> >::value;
00878 
00879   /**
00880    * Stores a tuple of indices. Used by bind() to extract the elements
00881    * in a tuple. 
00882    */
00883   template<int... _Indexes>
00884     struct _Index_tuple { };
00885 
00886   /// Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
00887   template<std::size_t _Num, typename _Tuple = _Index_tuple<> >
00888     struct _Build_index_tuple;
00889  
00890   template<std::size_t _Num, int... _Indexes> 
00891     struct _Build_index_tuple<_Num, _Index_tuple<_Indexes...> >
00892     : _Build_index_tuple<_Num - 1, 
00893                          _Index_tuple<_Indexes..., sizeof...(_Indexes)> >
00894     {
00895     };
00896 
00897   template<int... _Indexes>
00898     struct _Build_index_tuple<0, _Index_tuple<_Indexes...> >
00899     {
00900       typedef _Index_tuple<_Indexes...> __type;
00901     };
00902 
00903   /** 
00904    * Used by _Safe_tuple_element to indicate that there is no tuple
00905    * element at this position.
00906    */
00907   struct _No_tuple_element;
00908 
00909   /**
00910    * Implementation helper for _Safe_tuple_element. This primary
00911    * template handles the case where it is safe to use @c
00912    * tuple_element.
00913    */
00914   template<int __i, typename _Tuple, bool _IsSafe>
00915     struct _Safe_tuple_element_impl
00916     : tuple_element<__i, _Tuple> { };
00917 
00918   /**
00919    * Implementation helper for _Safe_tuple_element. This partial
00920    * specialization handles the case where it is not safe to use @c
00921    * tuple_element. We just return @c _No_tuple_element.
00922    */
00923   template<int __i, typename _Tuple>
00924     struct _Safe_tuple_element_impl<__i, _Tuple, false>
00925     {
00926       typedef _No_tuple_element type;
00927     };
00928 
00929   /**
00930    * Like tuple_element, but returns @c _No_tuple_element when
00931    * tuple_element would return an error.
00932    */
00933  template<int __i, typename _Tuple>
00934    struct _Safe_tuple_element
00935    : _Safe_tuple_element_impl<__i, _Tuple, 
00936                               (__i >= 0 && __i < tuple_size<_Tuple>::value)>
00937    {
00938    };
00939 
00940   /**
00941    *  Maps an argument to bind() into an actual argument to the bound
00942    *  function object [TR1 3.6.3/5]. Only the first parameter should
00943    *  be specified: the rest are used to determine among the various
00944    *  implementations. Note that, although this class is a function
00945    *  object, it isn't entirely normal because it takes only two
00946    *  parameters regardless of the number of parameters passed to the
00947    *  bind expression. The first parameter is the bound argument and
00948    *  the second parameter is a tuple containing references to the
00949    *  rest of the arguments.
00950    */
00951   template<typename _Arg,
00952            bool _IsBindExp = is_bind_expression<_Arg>::value,
00953            bool _IsPlaceholder = (is_placeholder<_Arg>::value > 0)>
00954     class _Mu;
00955 
00956   /**
00957    *  If the argument is reference_wrapper<_Tp>, returns the
00958    *  underlying reference. [TR1 3.6.3/5 bullet 1]
00959    */
00960   template<typename _Tp>
00961     class _Mu<reference_wrapper<_Tp>, false, false>
00962     {
00963     public:
00964       typedef _Tp& result_type;
00965 
00966       /* Note: This won't actually work for const volatile
00967        * reference_wrappers, because reference_wrapper::get() is const
00968        * but not volatile-qualified. This might be a defect in the TR.
00969        */
00970       template<typename _CVRef, typename _Tuple>
00971         result_type
00972         operator()(_CVRef& __arg, const _Tuple&) const volatile
00973         { return __arg.get(); }
00974     };
00975 
00976   /**
00977    *  If the argument is a bind expression, we invoke the underlying
00978    *  function object with the same cv-qualifiers as we are given and
00979    *  pass along all of our arguments (unwrapped). [TR1 3.6.3/5 bullet 2]
00980    */
00981   template<typename _Arg>
00982     class _Mu<_Arg, true, false>
00983     {
00984     public:
00985       template<typename _Signature> class result;
00986 
00987       // Determine the result type when we pass the arguments along. This
00988       // involves passing along the cv-qualifiers placed on _Mu and
00989       // unwrapping the argument bundle.
00990       template<typename _CVMu, typename _CVArg, typename... _Args>
00991         class result<_CVMu(_CVArg, tuple<_Args...>)>
00992     : public result_of<_CVArg(_Args...)> { };
00993 
00994       template<typename _CVArg, typename... _Args>
00995         typename result_of<_CVArg(_Args...)>::type
00996         operator()(_CVArg& __arg,
00997            const tuple<_Args...>& __tuple) const volatile
00998         {
00999       // Construct an index tuple and forward to __call
01000       typedef typename _Build_index_tuple<sizeof...(_Args)>::__type
01001         _Indexes;
01002       return this->__call(__arg, __tuple, _Indexes());
01003     }
01004 
01005     private:
01006       // Invokes the underlying function object __arg by unpacking all
01007       // of the arguments in the tuple. 
01008       template<typename _CVArg, typename... _Args, int... _Indexes>
01009         typename result_of<_CVArg(_Args...)>::type
01010         __call(_CVArg& __arg, const tuple<_Args...>& __tuple,
01011            const _Index_tuple<_Indexes...>&) const volatile
01012         {
01013       return __arg(_GLIBCXX_TR1 get<_Indexes>(__tuple)...);
01014     }
01015     };
01016 
01017   /**
01018    *  If the argument is a placeholder for the Nth argument, returns
01019    *  a reference to the Nth argument to the bind function object.
01020    *  [TR1 3.6.3/5 bullet 3]
01021    */
01022   template<typename _Arg>
01023     class _Mu<_Arg, false, true>
01024     {
01025     public:
01026       template<typename _Signature> class result;
01027 
01028       template<typename _CVMu, typename _CVArg, typename _Tuple>
01029         class result<_CVMu(_CVArg, _Tuple)>
01030         {
01031       // Add a reference, if it hasn't already been done for us.
01032       // This allows us to be a little bit sloppy in constructing
01033       // the tuple that we pass to result_of<...>.
01034       typedef typename _Safe_tuple_element<(is_placeholder<_Arg>::value
01035                         - 1), _Tuple>::type
01036         __base_type;
01037 
01038     public:
01039 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
01040       typedef typename add_lvalue_reference<__base_type>::type type;
01041 #else
01042       typedef typename add_reference<__base_type>::type type;
01043 #endif
01044     };
01045 
01046       template<typename _Tuple>
01047         typename result<_Mu(_Arg, _Tuple)>::type
01048         operator()(const volatile _Arg&, const _Tuple& __tuple) const volatile
01049         {
01050       return ::std::_GLIBCXX_TR1 get<(is_placeholder<_Arg>::value
01051                       - 1)>(__tuple);
01052     }
01053     };
01054 
01055   /**
01056    *  If the argument is just a value, returns a reference to that
01057    *  value. The cv-qualifiers on the reference are the same as the
01058    *  cv-qualifiers on the _Mu object. [TR1 3.6.3/5 bullet 4]
01059    */
01060   template<typename _Arg>
01061     class _Mu<_Arg, false, false>
01062     {
01063     public:
01064       template<typename _Signature> struct result;
01065 
01066       template<typename _CVMu, typename _CVArg, typename _Tuple>
01067         struct result<_CVMu(_CVArg, _Tuple)>
01068         {
01069 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
01070       typedef typename add_lvalue_reference<_CVArg>::type type;
01071 #else
01072       typedef typename add_reference<_CVArg>::type type;
01073 #endif
01074     };
01075 
01076       // Pick up the cv-qualifiers of the argument
01077       template<typename _CVArg, typename _Tuple>
01078         _CVArg&
01079         operator()(_CVArg& __arg, const _Tuple&) const volatile
01080         { return __arg; }
01081     };
01082 
01083   /**
01084    *  Maps member pointers into instances of _Mem_fn but leaves all
01085    *  other function objects untouched. Used by tr1::bind(). The
01086    *  primary template handles the non--member-pointer case.
01087    */
01088   template<typename _Tp>
01089     struct _Maybe_wrap_member_pointer
01090     {
01091       typedef _Tp type;
01092       
01093       static const _Tp&
01094       __do_wrap(const _Tp& __x)
01095       { return __x; }
01096     };
01097 
01098   /**
01099    *  Maps member pointers into instances of _Mem_fn but leaves all
01100    *  other function objects untouched. Used by tr1::bind(). This
01101    *  partial specialization handles the member pointer case.
01102    */
01103   template<typename _Tp, typename _Class>
01104     struct _Maybe_wrap_member_pointer<_Tp _Class::*>
01105     {
01106       typedef _Mem_fn<_Tp _Class::*> type;
01107       
01108       static type
01109       __do_wrap(_Tp _Class::* __pm)
01110       { return type(__pm); }
01111     };
01112 
01113   /// Type of the function object returned from bind().
01114   template<typename _Signature>
01115     struct _Bind;
01116 
01117    template<typename _Functor, typename... _Bound_args>
01118     class _Bind<_Functor(_Bound_args...)>
01119     : public _Weak_result_type<_Functor>
01120     {
01121       typedef _Bind __self_type;
01122       typedef typename _Build_index_tuple<sizeof...(_Bound_args)>::__type 
01123         _Bound_indexes;
01124 
01125       _Functor _M_f;
01126       tuple<_Bound_args...> _M_bound_args;
01127 
01128       // Call unqualified
01129       template<typename... _Args, int... _Indexes>
01130         typename result_of<
01131                    _Functor(typename result_of<_Mu<_Bound_args> 
01132                             (_Bound_args, tuple<_Args...>)>::type...)
01133                  >::type
01134         __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>)
01135         {
01136           return _M_f(_Mu<_Bound_args>()
01137                       (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01138         }
01139 
01140       // Call as const
01141       template<typename... _Args, int... _Indexes>
01142         typename result_of<
01143                    const _Functor(typename result_of<_Mu<_Bound_args> 
01144                                     (const _Bound_args, tuple<_Args...>)
01145                                   >::type...)>::type
01146         __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const
01147         {
01148           return _M_f(_Mu<_Bound_args>()
01149                       (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01150         }
01151 
01152       // Call as volatile
01153       template<typename... _Args, int... _Indexes>
01154         typename result_of<
01155                    volatile _Functor(typename result_of<_Mu<_Bound_args> 
01156                                     (volatile _Bound_args, tuple<_Args...>)
01157                                   >::type...)>::type
01158         __call(const tuple<_Args...>& __args, 
01159                _Index_tuple<_Indexes...>) volatile
01160         {
01161           return _M_f(_Mu<_Bound_args>()
01162                       (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01163         }
01164 
01165       // Call as const volatile
01166       template<typename... _Args, int... _Indexes>
01167         typename result_of<
01168                    const volatile _Functor(typename result_of<_Mu<_Bound_args> 
01169                                     (const volatile _Bound_args, 
01170                                      tuple<_Args...>)
01171                                   >::type...)>::type
01172         __call(const tuple<_Args...>& __args, 
01173                _Index_tuple<_Indexes...>) const volatile
01174         {
01175           return _M_f(_Mu<_Bound_args>()
01176                       (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01177         }
01178 
01179      public:
01180       explicit _Bind(_Functor __f, _Bound_args... __bound_args)
01181         : _M_f(__f), _M_bound_args(__bound_args...) { }
01182 
01183       // Call unqualified
01184       template<typename... _Args>
01185         typename result_of<
01186                    _Functor(typename result_of<_Mu<_Bound_args> 
01187                             (_Bound_args, tuple<_Args...>)>::type...)
01188                  >::type
01189         operator()(_Args&... __args)
01190         {
01191           return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01192         }
01193 
01194       // Call as const
01195       template<typename... _Args>
01196         typename result_of<
01197                    const _Functor(typename result_of<_Mu<_Bound_args> 
01198                             (const _Bound_args, tuple<_Args...>)>::type...)
01199                  >::type
01200         operator()(_Args&... __args) const
01201         {
01202           return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01203         }
01204 
01205 
01206       // Call as volatile
01207       template<typename... _Args>
01208         typename result_of<
01209                    volatile _Functor(typename result_of<_Mu<_Bound_args> 
01210                             (volatile _Bound_args, tuple<_Args...>)>::type...)
01211                  >::type
01212         operator()(_Args&... __args) volatile
01213         {
01214           return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01215         }
01216 
01217 
01218       // Call as const volatile
01219       template<typename... _Args>
01220         typename result_of<
01221                    const volatile _Functor(typename result_of<_Mu<_Bound_args> 
01222                             (const volatile _Bound_args, 
01223                              tuple<_Args...>)>::type...)
01224                  >::type
01225         operator()(_Args&... __args) const volatile
01226         {
01227           return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01228         }
01229     };
01230 
01231   /// Type of the function object returned from bind<R>().
01232   template<typename _Result, typename _Signature>
01233     struct _Bind_result;
01234 
01235   template<typename _Result, typename _Functor, typename... _Bound_args>
01236     class _Bind_result<_Result, _Functor(_Bound_args...)>
01237     {
01238       typedef _Bind_result __self_type;
01239       typedef typename _Build_index_tuple<sizeof...(_Bound_args)>::__type 
01240         _Bound_indexes;
01241 
01242       _Functor _M_f;
01243       tuple<_Bound_args...> _M_bound_args;
01244 
01245       // Call unqualified
01246       template<typename... _Args, int... _Indexes>
01247         _Result
01248         __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>)
01249         {
01250           return _M_f(_Mu<_Bound_args>()
01251                       (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01252         }
01253 
01254       // Call as const
01255       template<typename... _Args, int... _Indexes>
01256         _Result
01257         __call(const tuple<_Args...>& __args, _Index_tuple<_Indexes...>) const
01258         {
01259           return _M_f(_Mu<_Bound_args>()
01260                       (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01261         }
01262 
01263       // Call as volatile
01264       template<typename... _Args, int... _Indexes>
01265         _Result
01266         __call(const tuple<_Args...>& __args, 
01267                _Index_tuple<_Indexes...>) volatile
01268         {
01269           return _M_f(_Mu<_Bound_args>()
01270                       (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01271         }
01272 
01273       // Call as const volatile
01274       template<typename... _Args, int... _Indexes>
01275         _Result
01276         __call(const tuple<_Args...>& __args, 
01277                _Index_tuple<_Indexes...>) const volatile
01278         {
01279           return _M_f(_Mu<_Bound_args>()
01280                       (_GLIBCXX_TR1 get<_Indexes>(_M_bound_args), __args)...);
01281         }
01282 
01283     public:
01284       typedef _Result result_type;
01285 
01286       explicit
01287       _Bind_result(_Functor __f, _Bound_args... __bound_args)
01288       : _M_f(__f), _M_bound_args(__bound_args...) { }
01289 
01290       // Call unqualified
01291       template<typename... _Args>
01292         result_type
01293         operator()(_Args&... __args)
01294         {
01295           return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01296         }
01297 
01298       // Call as const
01299       template<typename... _Args>
01300         result_type
01301         operator()(_Args&... __args) const
01302         {
01303           return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01304         }
01305 
01306       // Call as volatile
01307       template<typename... _Args>
01308         result_type
01309         operator()(_Args&... __args) volatile
01310         {
01311           return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01312         }
01313 
01314       // Call as const volatile
01315       template<typename... _Args>
01316         result_type
01317         operator()(_Args&... __args) const volatile
01318         {
01319           return this->__call(_GLIBCXX_TR1 tie(__args...), _Bound_indexes());
01320         }
01321     };
01322 
01323   /// Class template _Bind is always a bind expression.
01324   template<typename _Signature>
01325     struct is_bind_expression<_Bind<_Signature> >
01326     { static const bool value = true; };
01327 
01328   template<typename _Signature>
01329     const bool is_bind_expression<_Bind<_Signature> >::value;
01330 
01331   /// Class template _Bind_result is always a bind expression.
01332   template<typename _Result, typename _Signature>
01333     struct is_bind_expression<_Bind_result<_Result, _Signature> >
01334     { static const bool value = true; };
01335 
01336   template<typename _Result, typename _Signature>
01337     const bool is_bind_expression<_Bind_result<_Result, _Signature> >::value;
01338 
01339   /// bind
01340   template<typename _Functor, typename... _ArgTypes>
01341     inline
01342     _Bind<typename _Maybe_wrap_member_pointer<_Functor>::type(_ArgTypes...)>
01343     bind(_Functor __f, _ArgTypes... __args)
01344     {
01345       typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
01346       typedef typename __maybe_type::type __functor_type;
01347       typedef _Bind<__functor_type(_ArgTypes...)> __result_type;
01348       return __result_type(__maybe_type::__do_wrap(__f), __args...);
01349     } 
01350 
01351   template<typename _Result, typename _Functor, typename... _ArgTypes>
01352     inline
01353     _Bind_result<_Result,
01354          typename _Maybe_wrap_member_pointer<_Functor>::type
01355                             (_ArgTypes...)>
01356     bind(_Functor __f, _ArgTypes... __args)
01357     {
01358       typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;
01359       typedef typename __maybe_type::type __functor_type;
01360       typedef _Bind_result<_Result, __functor_type(_ArgTypes...)>
01361     __result_type;
01362       return __result_type(__maybe_type::__do_wrap(__f), __args...);
01363     }
01364 
01365   /**
01366    *  @brief Exception class thrown when class template function's
01367    *  operator() is called with an empty target.
01368    *
01369    */
01370   class bad_function_call : public std::exception { };
01371 
01372   /**
01373    *  The integral constant expression 0 can be converted into a
01374    *  pointer to this type. It is used by the function template to
01375    *  accept NULL pointers.
01376    */
01377   struct _M_clear_type;
01378 
01379   /**
01380    *  Trait identifying "location-invariant" types, meaning that the
01381    *  address of the object (or any of its members) will not escape.
01382    *  Also implies a trivial copy constructor and assignment operator.
01383    */
01384   template<typename _Tp>
01385     struct __is_location_invariant
01386     : integral_constant<bool,
01387                         (is_pointer<_Tp>::value
01388                          || is_member_pointer<_Tp>::value)>
01389     {
01390     };
01391 
01392   class _Undefined_class;
01393 
01394   union _Nocopy_types
01395   {
01396     void*       _M_object;
01397     const void* _M_const_object;
01398     void (*_M_function_pointer)();
01399     void (_Undefined_class::*_M_member_pointer)();
01400   };
01401 
01402   union _Any_data
01403   {
01404     void*       _M_access()       { return &_M_pod_data[0]; }
01405     const void* _M_access() const { return &_M_pod_data[0]; }
01406 
01407     template<typename _Tp>
01408       _Tp&
01409       _M_access()
01410       { return *static_cast<_Tp*>(_M_access()); }
01411 
01412     template<typename _Tp>
01413       const _Tp&
01414       _M_access() const
01415       { return *static_cast<const _Tp*>(_M_access()); }
01416 
01417     _Nocopy_types _M_unused;
01418     char _M_pod_data[sizeof(_Nocopy_types)];
01419   };
01420 
01421   enum _Manager_operation
01422   {
01423     __get_type_info,
01424     __get_functor_ptr,
01425     __clone_functor,
01426     __destroy_functor
01427   };
01428 
01429   // Simple type wrapper that helps avoid annoying const problems
01430   // when casting between void pointers and pointers-to-pointers.
01431   template<typename _Tp>
01432     struct _Simple_type_wrapper
01433     {
01434       _Simple_type_wrapper(_Tp __value) : __value(__value) { }
01435 
01436       _Tp __value;
01437     };
01438 
01439   template<typename _Tp>
01440     struct __is_location_invariant<_Simple_type_wrapper<_Tp> >
01441     : __is_location_invariant<_Tp>
01442     {
01443     };
01444 
01445   // Converts a reference to a function object into a callable
01446   // function object.
01447   template<typename _Functor>
01448     inline _Functor&
01449     __callable_functor(_Functor& __f)
01450     { return __f; }
01451 
01452   template<typename _Member, typename _Class>
01453     inline _Mem_fn<_Member _Class::*>
01454     __callable_functor(_Member _Class::* &__p)
01455     { return mem_fn(__p); }
01456 
01457   template<typename _Member, typename _Class>
01458     inline _Mem_fn<_Member _Class::*>
01459     __callable_functor(_Member _Class::* const &__p)
01460     { return mem_fn(__p); }
01461 
01462   template<typename _Signature>
01463     class function;
01464 
01465   /// Base class of all polymorphic function object wrappers.
01466   class _Function_base
01467   {
01468   public:
01469     static const std::size_t _M_max_size = sizeof(_Nocopy_types);
01470     static const std::size_t _M_max_align = __alignof__(_Nocopy_types);
01471 
01472     template<typename _Functor>
01473       class _Base_manager
01474       {
01475       protected:
01476     static const bool __stored_locally =
01477         (__is_location_invariant<_Functor>::value
01478          && sizeof(_Functor) <= _M_max_size
01479          && __alignof__(_Functor) <= _M_max_align
01480          && (_M_max_align % __alignof__(_Functor) == 0));
01481     
01482     typedef integral_constant<bool, __stored_locally> _Local_storage;
01483 
01484     // Retrieve a pointer to the function object
01485     static _Functor*
01486     _M_get_pointer(const _Any_data& __source)
01487     {
01488       const _Functor* __ptr =
01489         __stored_locally? &__source._M_access<_Functor>()
01490         /* have stored a pointer */ : __source._M_access<_Functor*>();
01491       return const_cast<_Functor*>(__ptr);
01492     }
01493 
01494     // Clone a location-invariant function object that fits within
01495     // an _Any_data structure.
01496     static void
01497     _M_clone(_Any_data& __dest, const _Any_data& __source, true_type)
01498     {
01499       new (__dest._M_access()) _Functor(__source._M_access<_Functor>());
01500     }
01501 
01502     // Clone a function object that is not location-invariant or
01503     // that cannot fit into an _Any_data structure.
01504     static void
01505     _M_clone(_Any_data& __dest, const _Any_data& __source, false_type)
01506     {
01507       __dest._M_access<_Functor*>() =
01508         new _Functor(*__source._M_access<_Functor*>());
01509     }
01510 
01511     // Destroying a location-invariant object may still require
01512     // destruction.
01513     static void
01514     _M_destroy(_Any_data& __victim, true_type)
01515     {
01516       __victim._M_access<_Functor>().~_Functor();
01517     }
01518     
01519     // Destroying an object located on the heap.
01520     static void
01521     _M_destroy(_Any_data& __victim, false_type)
01522     {
01523       delete __victim._M_access<_Functor*>();
01524     }
01525     
01526       public:
01527     static bool
01528     _M_manager(_Any_data& __dest, const _Any_data& __source,
01529            _Manager_operation __op)
01530     {
01531       switch (__op)
01532         {
01533 #ifdef __GXX_RTTI
01534         case __get_type_info:
01535           __dest._M_access<const type_info*>() = &typeid(_Functor);
01536           break;
01537 #endif
01538         case __get_functor_ptr:
01539           __dest._M_access<_Functor*>() = _M_get_pointer(__source);
01540           break;
01541           
01542         case __clone_functor:
01543           _M_clone(__dest, __source, _Local_storage());
01544           break;
01545 
01546         case __destroy_functor:
01547           _M_destroy(__dest, _Local_storage());
01548           break;
01549         }
01550       return false;
01551     }
01552 
01553     static void
01554     _M_init_functor(_Any_data& __functor, const _Functor& __f)
01555     { _M_init_functor(__functor, __f, _Local_storage()); }
01556     
01557     template<typename _Signature>
01558       static bool
01559       _M_not_empty_function(const function<_Signature>& __f)
01560       { return __f; }
01561 
01562     template<typename _Tp>
01563       static bool
01564       _M_not_empty_function(const _Tp*& __fp)
01565       { return __fp; }
01566 
01567     template<typename _Class, typename _Tp>
01568       static bool
01569       _M_not_empty_function(_Tp _Class::* const& __mp)
01570       { return __mp; }
01571 
01572     template<typename _Tp>
01573       static bool
01574       _M_not_empty_function(const _Tp&)
01575       { return true; }
01576 
01577       private:
01578     static void
01579     _M_init_functor(_Any_data& __functor, const _Functor& __f, true_type)
01580     { new (__functor._M_access()) _Functor(__f); }
01581 
01582     static void
01583     _M_init_functor(_Any_data& __functor, const _Functor& __f, false_type)
01584     { __functor._M_access<_Functor*>() = new _Functor(__f); }
01585       };
01586 
01587     template<typename _Functor>
01588       class _Ref_manager : public _Base_manager<_Functor*>
01589       {
01590     typedef _Function_base::_Base_manager<_Functor*> _Base;
01591 
01592     public:
01593     static bool
01594     _M_manager(_Any_data& __dest, const _Any_data& __source,
01595            _Manager_operation __op)
01596     {
01597       switch (__op)
01598         {
01599 #ifdef __GXX_RTTI
01600         case __get_type_info:
01601           __dest._M_access<const type_info*>() = &typeid(_Functor);
01602           break;
01603 #endif
01604         case __get_functor_ptr:
01605           __dest._M_access<_Functor*>() = *_Base::_M_get_pointer(__source);
01606           return is_const<_Functor>::value;
01607           break;
01608           
01609         default:
01610           _Base::_M_manager(__dest, __source, __op);
01611         }
01612       return false;
01613     }
01614 
01615     static void
01616     _M_init_functor(_Any_data& __functor, reference_wrapper<_Functor> __f)
01617     {
01618       // TBD: Use address_of function instead.
01619       _Base::_M_init_functor(__functor, &__f.get());
01620     }
01621       };
01622 
01623     _Function_base() : _M_manager(0) { }
01624     
01625     ~_Function_base()
01626     {
01627       if (_M_manager)
01628     _M_manager(_M_functor, _M_functor, __destroy_functor);
01629     }
01630 
01631 
01632     bool _M_empty() const { return !_M_manager; }
01633 
01634     typedef bool (*_Manager_type)(_Any_data&, const _Any_data&,
01635                                   _Manager_operation);
01636 
01637     _Any_data     _M_functor;
01638     _Manager_type _M_manager;
01639   };
01640 
01641   template<typename _Signature, typename _Functor>
01642     class _Function_handler;
01643 
01644   template<typename _Res, typename _Functor, typename... _ArgTypes>
01645     class _Function_handler<_Res(_ArgTypes...), _Functor>
01646     : public _Function_base::_Base_manager<_Functor>
01647     {
01648       typedef _Function_base::_Base_manager<_Functor> _Base;
01649 
01650     public:
01651       static _Res
01652       _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01653       {
01654         return (*_Base::_M_get_pointer(__functor))(__args...);
01655       }
01656     };
01657 
01658   template<typename _Functor, typename... _ArgTypes>
01659     class _Function_handler<void(_ArgTypes...), _Functor>
01660     : public _Function_base::_Base_manager<_Functor>
01661     {
01662       typedef _Function_base::_Base_manager<_Functor> _Base;
01663 
01664      public:
01665       static void
01666       _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01667       {
01668         (*_Base::_M_get_pointer(__functor))(__args...);
01669       }
01670     };
01671 
01672   template<typename _Res, typename _Functor, typename... _ArgTypes>
01673     class _Function_handler<_Res(_ArgTypes...), reference_wrapper<_Functor> >
01674     : public _Function_base::_Ref_manager<_Functor>
01675     {
01676       typedef _Function_base::_Ref_manager<_Functor> _Base;
01677 
01678      public:
01679       static _Res
01680       _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01681       {
01682         return 
01683           __callable_functor(**_Base::_M_get_pointer(__functor))(__args...);
01684       }
01685     };
01686 
01687   template<typename _Functor, typename... _ArgTypes>
01688     class _Function_handler<void(_ArgTypes...), reference_wrapper<_Functor> >
01689     : public _Function_base::_Ref_manager<_Functor>
01690     {
01691       typedef _Function_base::_Ref_manager<_Functor> _Base;
01692 
01693      public:
01694       static void
01695       _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01696       {
01697         __callable_functor(**_Base::_M_get_pointer(__functor))(__args...);
01698       }
01699     };
01700 
01701   template<typename _Class, typename _Member, typename _Res, 
01702            typename... _ArgTypes>
01703     class _Function_handler<_Res(_ArgTypes...), _Member _Class::*>
01704     : public _Function_handler<void(_ArgTypes...), _Member _Class::*>
01705     {
01706       typedef _Function_handler<void(_ArgTypes...), _Member _Class::*>
01707         _Base;
01708 
01709      public:
01710       static _Res
01711       _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01712       {
01713         return _GLIBCXX_TR1
01714       mem_fn(_Base::_M_get_pointer(__functor)->__value)(__args...);
01715       }
01716     };
01717 
01718   template<typename _Class, typename _Member, typename... _ArgTypes>
01719     class _Function_handler<void(_ArgTypes...), _Member _Class::*>
01720     : public _Function_base::_Base_manager<
01721                  _Simple_type_wrapper< _Member _Class::* > >
01722     {
01723       typedef _Member _Class::* _Functor;
01724       typedef _Simple_type_wrapper<_Functor> _Wrapper;
01725       typedef _Function_base::_Base_manager<_Wrapper> _Base;
01726 
01727      public:
01728       static bool
01729       _M_manager(_Any_data& __dest, const _Any_data& __source,
01730                  _Manager_operation __op)
01731       {
01732         switch (__op)
01733       {
01734 #ifdef __GXX_RTTI
01735       case __get_type_info:
01736         __dest._M_access<const type_info*>() = &typeid(_Functor);
01737         break;
01738 #endif      
01739       case __get_functor_ptr:
01740         __dest._M_access<_Functor*>() =
01741           &_Base::_M_get_pointer(__source)->__value;
01742         break;
01743         
01744       default:
01745         _Base::_M_manager(__dest, __source, __op);
01746       }
01747         return false;
01748       }
01749 
01750       static void
01751       _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
01752       {
01753         _GLIBCXX_TR1
01754       mem_fn(_Base::_M_get_pointer(__functor)->__value)(__args...);
01755       }
01756     };
01757 
01758   /// class function
01759   template<typename _Res, typename... _ArgTypes>
01760     class function<_Res(_ArgTypes...)>
01761     : public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>,
01762       private _Function_base
01763     {
01764       /// This class is used to implement the safe_bool idiom.
01765       struct _Hidden_type
01766       {
01767     _Hidden_type* _M_bool;
01768       };
01769 
01770       /// This typedef is used to implement the safe_bool idiom.
01771       typedef _Hidden_type* _Hidden_type::* _Safe_bool;
01772 
01773       typedef _Res _Signature_type(_ArgTypes...);
01774       
01775       struct _Useless { };
01776       
01777     public:
01778       typedef _Res result_type;
01779       
01780       // [3.7.2.1] construct/copy/destroy
01781       
01782       /**
01783        *  @brief Default construct creates an empty function call wrapper.
01784        *  @post @c !(bool)*this
01785        */
01786       function() : _Function_base() { }
01787       
01788       /**
01789        *  @brief Default construct creates an empty function call wrapper.
01790        *  @post @c !(bool)*this
01791        */
01792       function(_M_clear_type*) : _Function_base() { }
01793       
01794       /**
01795        *  @brief %Function copy constructor.
01796        *  @param x A %function object with identical call signature.
01797        *  @pre @c (bool)*this == (bool)x
01798        *
01799        *  The newly-created %function contains a copy of the target of @a
01800        *  x (if it has one).
01801        */
01802       function(const function& __x);
01803       
01804       /**
01805        *  @brief Builds a %function that targets a copy of the incoming
01806        *  function object.
01807        *  @param f A %function object that is callable with parameters of
01808        *  type @c T1, @c T2, ..., @c TN and returns a value convertible
01809        *  to @c Res.
01810        *
01811        *  The newly-created %function object will target a copy of @a
01812        *  f. If @a f is @c reference_wrapper<F>, then this function
01813        *  object will contain a reference to the function object @c
01814        *  f.get(). If @a f is a NULL function pointer or NULL
01815        *  pointer-to-member, the newly-created object will be empty.
01816        *
01817        *  If @a f is a non-NULL function pointer or an object of type @c
01818        *  reference_wrapper<F>, this function will not throw.
01819        */
01820       template<typename _Functor>
01821         function(_Functor __f,
01822                  typename __gnu_cxx::__enable_if<
01823                            !is_integral<_Functor>::value, _Useless>::__type
01824                    = _Useless());
01825 
01826       /**
01827        *  @brief %Function assignment operator.
01828        *  @param x A %function with identical call signature.
01829        *  @post @c (bool)*this == (bool)x
01830        *  @returns @c *this
01831        *
01832        *  The target of @a x is copied to @c *this. If @a x has no
01833        *  target, then @c *this will be empty.
01834        *
01835        *  If @a x targets a function pointer or a reference to a function
01836        *  object, then this operation will not throw an exception.
01837        */
01838       function&
01839       operator=(const function& __x)
01840       {
01841         function(__x).swap(*this);
01842         return *this;
01843       }
01844 
01845       /**
01846        *  @brief %Function assignment to zero.
01847        *  @post @c !(bool)*this
01848        *  @returns @c *this
01849        *
01850        *  The target of @a *this is deallocated, leaving it empty.
01851        */
01852       function&
01853       operator=(_M_clear_type*)
01854       {
01855         if (_M_manager)
01856       {
01857         _M_manager(_M_functor, _M_functor, __destroy_functor);
01858         _M_manager = 0;
01859         _M_invoker = 0;
01860       }
01861         return *this;
01862       }
01863 
01864       /**
01865        *  @brief %Function assignment to a new target.
01866        *  @param f A %function object that is callable with parameters of
01867        *  type @c T1, @c T2, ..., @c TN and returns a value convertible
01868        *  to @c Res.
01869        *  @return @c *this
01870        *
01871        *  This  %function object wrapper will target a copy of @a
01872        *  f. If @a f is @c reference_wrapper<F>, then this function
01873        *  object will contain a reference to the function object @c
01874        *  f.get(). If @a f is a NULL function pointer or NULL
01875        *  pointer-to-member, @c this object will be empty.
01876        *
01877        *  If @a f is a non-NULL function pointer or an object of type @c
01878        *  reference_wrapper<F>, this function will not throw.
01879        */
01880       template<typename _Functor>
01881         typename __gnu_cxx::__enable_if<!is_integral<_Functor>::value,
01882                                     function&>::__type
01883     operator=(_Functor __f)
01884     {
01885       function(__f).swap(*this);
01886       return *this;
01887     }
01888 
01889       // [3.7.2.2] function modifiers
01890       
01891       /**
01892        *  @brief Swap the targets of two %function objects.
01893        *  @param f A %function with identical call signature.
01894        *
01895        *  Swap the targets of @c this function object and @a f. This
01896        *  function will not throw an exception.
01897        */
01898       void swap(function& __x)
01899       {
01900     _Any_data __old_functor = _M_functor;
01901     _M_functor = __x._M_functor;
01902     __x._M_functor = __old_functor;
01903     _Manager_type __old_manager = _M_manager;
01904     _M_manager = __x._M_manager;
01905     __x._M_manager = __old_manager;
01906     _Invoker_type __old_invoker = _M_invoker;
01907     _M_invoker = __x._M_invoker;
01908     __x._M_invoker = __old_invoker;
01909       }
01910       
01911       // [3.7.2.3] function capacity
01912 
01913       /**
01914        *  @brief Determine if the %function wrapper has a target.
01915        *
01916        *  @return @c true when this %function object contains a target,
01917        *  or @c false when it is empty.
01918        *
01919        *  This function will not throw an exception.
01920        */
01921       operator _Safe_bool() const
01922       {
01923         if (_M_empty())
01924       return 0;
01925     else
01926       return &_Hidden_type::_M_bool;
01927       }
01928 
01929       // [3.7.2.4] function invocation
01930 
01931       /**
01932        *  @brief Invokes the function targeted by @c *this.
01933        *  @returns the result of the target.
01934        *  @throws bad_function_call when @c !(bool)*this
01935        *
01936        *  The function call operator invokes the target function object
01937        *  stored by @c this.
01938        */
01939       _Res operator()(_ArgTypes... __args) const;
01940 
01941 #ifdef __GXX_RTTI
01942       // [3.7.2.5] function target access
01943       /**
01944        *  @brief Determine the type of the target of this function object
01945        *  wrapper.
01946        *
01947        *  @returns the type identifier of the target function object, or
01948        *  @c typeid(void) if @c !(bool)*this.
01949        *
01950        *  This function will not throw an exception.
01951        */
01952       const type_info& target_type() const;
01953       
01954       /**
01955        *  @brief Access the stored target function object.
01956        *
01957        *  @return Returns a pointer to the stored target function object,
01958        *  if @c typeid(Functor).equals(target_type()); otherwise, a NULL
01959        *  pointer.
01960        *
01961        * This function will not throw an exception.
01962        */
01963       template<typename _Functor>       _Functor* target();
01964       
01965       /// @overload
01966       template<typename _Functor> const _Functor* target() const;
01967 #endif
01968 
01969     private:
01970       // [3.7.2.6] undefined operators
01971       template<typename _Function>
01972     void operator==(const function<_Function>&) const;
01973       template<typename _Function>
01974     void operator!=(const function<_Function>&) const;
01975 
01976       typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...);
01977       _Invoker_type _M_invoker;
01978   };
01979 
01980   template<typename _Res, typename... _ArgTypes>
01981     function<_Res(_ArgTypes...)>::
01982     function(const function& __x)
01983     : _Function_base()
01984     {
01985       if (__x)
01986     {
01987       _M_invoker = __x._M_invoker;
01988       _M_manager = __x._M_manager;
01989       __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
01990     }
01991     }
01992 
01993   template<typename _Res, typename... _ArgTypes>
01994     template<typename _Functor>
01995       function<_Res(_ArgTypes...)>::
01996       function(_Functor __f,
01997            typename __gnu_cxx::__enable_if<
01998                        !is_integral<_Functor>::value, _Useless>::__type)
01999       : _Function_base()
02000       {
02001     typedef _Function_handler<_Signature_type, _Functor> _My_handler;
02002 
02003     if (_My_handler::_M_not_empty_function(__f))
02004       {
02005         _M_invoker = &_My_handler::_M_invoke;
02006         _M_manager = &_My_handler::_M_manager;
02007         _My_handler::_M_init_functor(_M_functor, __f);
02008       }
02009       }
02010 
02011   template<typename _Res, typename... _ArgTypes>
02012     _Res
02013     function<_Res(_ArgTypes...)>::
02014     operator()(_ArgTypes... __args) const
02015     {
02016       if (_M_empty())
02017         {
02018 #if __EXCEPTIONS
02019           throw bad_function_call();
02020 #else
02021           __builtin_abort();
02022 #endif
02023         }
02024       return _M_invoker(_M_functor, __args...);
02025     }
02026 
02027 #ifdef __GXX_RTTI
02028   template<typename _Res, typename... _ArgTypes>
02029     const type_info&
02030     function<_Res(_ArgTypes...)>::
02031     target_type() const
02032     {
02033       if (_M_manager)
02034         {
02035           _Any_data __typeinfo_result;
02036           _M_manager(__typeinfo_result, _M_functor, __get_type_info);
02037           return *__typeinfo_result._M_access<const type_info*>();
02038         }
02039       else
02040     return typeid(void);
02041     }
02042 
02043   template<typename _Res, typename... _ArgTypes>
02044     template<typename _Functor>
02045       _Functor*
02046       function<_Res(_ArgTypes...)>::
02047       target()
02048       {
02049     if (typeid(_Functor) == target_type() && _M_manager)
02050       {
02051         _Any_data __ptr;
02052         if (_M_manager(__ptr, _M_functor, __get_functor_ptr)
02053         && !is_const<_Functor>::value)
02054           return 0;
02055         else
02056           return __ptr._M_access<_Functor*>();
02057       }
02058     else
02059       return 0;
02060       }
02061 
02062   template<typename _Res, typename... _ArgTypes>
02063     template<typename _Functor>
02064       const _Functor*
02065       function<_Res(_ArgTypes...)>::
02066       target() const
02067       {
02068     if (typeid(_Functor) == target_type() && _M_manager)
02069       {
02070         _Any_data __ptr;
02071         _M_manager(__ptr, _M_functor, __get_functor_ptr);
02072         return __ptr._M_access<const _Functor*>();
02073       }
02074     else
02075       return 0;
02076       }
02077 #endif
02078 
02079   // [3.7.2.7] null pointer comparisons
02080 
02081   /**
02082    *  @brief Compares a polymorphic function object wrapper against 0
02083    *  (the NULL pointer).
02084    *  @returns @c true if the wrapper has no target, @c false otherwise
02085    *
02086    *  This function will not throw an exception.
02087    */
02088   template<typename _Signature>
02089     inline bool
02090     operator==(const function<_Signature>& __f, _M_clear_type*)
02091     { return !__f; }
02092 
02093   /// @overload
02094   template<typename _Signature>
02095     inline bool
02096     operator==(_M_clear_type*, const function<_Signature>& __f)
02097     { return !__f; }
02098 
02099   /**
02100    *  @brief Compares a polymorphic function object wrapper against 0
02101    *  (the NULL pointer).
02102    *  @returns @c false if the wrapper has no target, @c true otherwise
02103    *
02104    *  This function will not throw an exception.
02105    */
02106   template<typename _Signature>
02107     inline bool
02108     operator!=(const function<_Signature>& __f, _M_clear_type*)
02109     { return __f; }
02110 
02111   /// @overload
02112   template<typename _Signature>
02113     inline bool
02114     operator!=(_M_clear_type*, const function<_Signature>& __f)
02115     { return __f; }
02116 
02117   // [3.7.2.8] specialized algorithms
02118 
02119   /**
02120    *  @brief Swap the targets of two polymorphic function object wrappers.
02121    *
02122    *  This function will not throw an exception.
02123    */
02124   template<typename _Signature>
02125     inline void
02126     swap(function<_Signature>& __x, function<_Signature>& __y)
02127     { __x.swap(__y); }
02128 
02129 _GLIBCXX_END_NAMESPACE_TR1
02130 }

Generated on Thu Jul 23 21:16:06 2009 for libstdc++ by  doxygen 1.5.8