tr1_impl/functional

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

Generated on Wed Mar 26 00:42:58 2008 for libstdc++ by  doxygen 1.5.1