⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functional_iterate.h

📁 linux下编程用 编译软件
💻 H
📖 第 1 页 / 共 2 页
字号:
// TR1 functional -*- C++ -*-// Copyright (C) 2005 Free Software Foundation, Inc.// Written by Douglas Gregor <doug.gregor -at- gmail.com>//// This file is part of the GNU ISO C++ Library.  This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License along// with this library; see the file COPYING.  If not, write to the Free// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,// USA.// As a special exception, you may use this file as part of a free software// library without restriction.  Specifically, if other files instantiate// templates or use macros or inline functions from this file, or you compile// this file and link it with other files to produce an executable, this// file does not by itself cause the resulting executable to be covered by// the GNU General Public License.  This exception does not however// invalidate any other reasons why the executable file might be covered by// the GNU General Public License./** @file functional_iterate.h *  This is an internal header file, included by other library headers. *  You should not attempt to use it directly. */template<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  struct _Weak_result_type_impl<_Res(_GLIBCXX_TEMPLATE_ARGS)>  {    typedef _Res result_type;  };template<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  struct _Weak_result_type_impl<_Res (&)(_GLIBCXX_TEMPLATE_ARGS)>  {    typedef _Res result_type;  };template<typename _Res _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  struct _Weak_result_type_impl<_Res (*)(_GLIBCXX_TEMPLATE_ARGS)>  {    typedef _Res result_type;  };#if _GLIBCXX_NUM_ARGS > 0template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>  struct _Weak_result_type_impl<           _Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED)>  {    typedef _Res result_type;  };template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>  struct _Weak_result_type_impl<           _Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const>  {    typedef _Res result_type;  };template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>  struct _Weak_result_type_impl<           _Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) volatile>  {    typedef _Res result_type;  };template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>  struct _Weak_result_type_impl<           _Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const volatile>  {    typedef _Res result_type;  };#endiftemplate<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  class result_of<_Functor(_GLIBCXX_TEMPLATE_ARGS)>    : public _Result_of_impl<               _Has_result_type<_Weak_result_type<_Functor> >::value,             _Functor(_GLIBCXX_TEMPLATE_ARGS)>  { };template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  struct _Result_of_impl<true, _Functor(_GLIBCXX_TEMPLATE_ARGS)>  {    typedef typename _Weak_result_type<_Functor>::result_type type;  };template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  struct _Result_of_impl<false, _Functor(_GLIBCXX_TEMPLATE_ARGS)>  {#if _GLIBCXX_NUM_ARGS > 0    typedef typename _Functor              ::template result<_Functor(_GLIBCXX_TEMPLATE_ARGS)>::type type;#else    typedef void type;#endif  };/** * @if maint * Invoke a function object, which may be either a member pointer or a * function object. The first parameter will tell which. * @endif */template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  inline  typename __enable_if<             typename result_of<_Functor(_GLIBCXX_TEMPLATE_ARGS)>::type,             (!is_member_pointer<_Functor>::value              && !is_function<_Functor>::value              && !is_function<typename remove_pointer<_Functor>::type>::value)           >::__type  __invoke(_Functor& __f _GLIBCXX_COMMA _GLIBCXX_REF_PARAMS)  {    return __f(_GLIBCXX_ARGS);  }#if _GLIBCXX_NUM_ARGS > 0template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  inline  typename __enable_if<             typename result_of<_Functor(_GLIBCXX_TEMPLATE_ARGS)>::type,             (is_member_pointer<_Functor>::value              && !is_function<_Functor>::value              && !is_function<typename remove_pointer<_Functor>::type>::value)           >::__type  __invoke(_Functor& __f _GLIBCXX_COMMA _GLIBCXX_REF_PARAMS)  {    return mem_fn(__f)(_GLIBCXX_ARGS);  }#endif// To pick up function references (that will become function pointers)template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>  inline  typename __enable_if<             typename result_of<_Functor(_GLIBCXX_TEMPLATE_ARGS)>::type,             (is_pointer<_Functor>::value              && is_function<typename remove_pointer<_Functor>::type>::value)           >::__type  __invoke(_Functor __f _GLIBCXX_COMMA _GLIBCXX_REF_PARAMS)  {    return __f(_GLIBCXX_ARGS);  }/** * @if maint * Implementation of reference_wrapper::operator() * @endif*/#if _GLIBCXX_NUM_ARGS > 0template<typename _Tp>template<_GLIBCXX_TEMPLATE_PARAMS>  typename result_of<   typename reference_wrapper<_Tp>::_M_func_type(_GLIBCXX_TEMPLATE_ARGS)>::type  reference_wrapper<_Tp>::operator()(_GLIBCXX_REF_PARAMS) const  {    return __invoke(get(), _GLIBCXX_ARGS);  }#endif#if _GLIBCXX_NUM_ARGS > 0template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>  class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED)>#if _GLIBCXX_NUM_ARGS == 1  : public unary_function<_Class*, _Res>#elif _GLIBCXX_NUM_ARGS == 2    : public binary_function<_Class*, _T1, _Res>#endif  {    typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED);    template<typename _Tp>      _Res      _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED              _GLIBCXX_PARAMS_SHIFTED) const      { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    template<typename _Tp>      _Res      _M_call(_Tp& __ptr, const volatile void * _GLIBCXX_COMMA_SHIFTED              _GLIBCXX_PARAMS_SHIFTED) const      {  return ((*__ptr).*__pmf)(_GLIBCXX_ARGS_SHIFTED); }  public:    typedef _Res result_type;    explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }    // Handle objects    _Res    operator()(_Class& __object _GLIBCXX_COMMA_SHIFTED               _GLIBCXX_PARAMS_SHIFTED) const    { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    // Handle pointers    _Res    operator()(_Class* __object _GLIBCXX_COMMA_SHIFTED               _GLIBCXX_PARAMS_SHIFTED) const    { return (__object->*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    // Handle smart pointers, references and pointers to derived    template<typename _Tp>      _Res      operator()(_Tp& __object _GLIBCXX_COMMA_SHIFTED                 _GLIBCXX_PARAMS_SHIFTED) const      {        return _M_call(__object, &__object _GLIBCXX_COMMA_SHIFTED                       _GLIBCXX_ARGS_SHIFTED);      }  private:    _Functor __pmf;  };template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>  class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const>#if _GLIBCXX_NUM_ARGS == 1  : public unary_function<const _Class*, _Res>#elif _GLIBCXX_NUM_ARGS == 2    : public binary_function<const _Class*, _T1, _Res>#endif  {    typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const;     template<typename _Tp>      _Res      _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED              _GLIBCXX_PARAMS_SHIFTED) const      { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    template<typename _Tp>      _Res      _M_call(_Tp& __ptr, const volatile void * _GLIBCXX_COMMA_SHIFTED              _GLIBCXX_PARAMS_SHIFTED) const      {  return ((*__ptr).*__pmf)(_GLIBCXX_ARGS_SHIFTED); }  public:    typedef _Res result_type;    explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }    // Handle objects    _Res    operator()(const _Class& __object _GLIBCXX_COMMA_SHIFTED               _GLIBCXX_PARAMS_SHIFTED) const    { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    // Handle pointers    _Res    operator()(const _Class* __object _GLIBCXX_COMMA_SHIFTED               _GLIBCXX_PARAMS_SHIFTED) const    { return (__object->*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    // Handle smart pointers, references and pointers to derived    template<typename _Tp>      _Res      operator()(_Tp& __object _GLIBCXX_COMMA_SHIFTED                 _GLIBCXX_PARAMS_SHIFTED) const      {        return _M_call(__object, &__object _GLIBCXX_COMMA_SHIFTED                       _GLIBCXX_ARGS_SHIFTED);      }  private:    _Functor __pmf;  };template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>  class _Mem_fn<_Res (_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) volatile>#if _GLIBCXX_NUM_ARGS == 1  : public unary_function<volatile _Class*, _Res>#elif _GLIBCXX_NUM_ARGS == 2    : public binary_function<volatile _Class*, _T1, _Res>#endif  {    typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) volatile;    template<typename _Tp>      _Res      _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED              _GLIBCXX_PARAMS_SHIFTED) const      { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    template<typename _Tp>      _Res      _M_call(_Tp& __ptr, const volatile void * _GLIBCXX_COMMA_SHIFTED              _GLIBCXX_PARAMS_SHIFTED) const      {  return ((*__ptr).*__pmf)(_GLIBCXX_ARGS_SHIFTED); }  public:    typedef _Res result_type;    explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }    // Handle objects    _Res    operator()(volatile _Class& __object _GLIBCXX_COMMA_SHIFTED               _GLIBCXX_PARAMS_SHIFTED) const    { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    // Handle pointers    _Res    operator()(volatile _Class* __object _GLIBCXX_COMMA_SHIFTED               _GLIBCXX_PARAMS_SHIFTED) const    { return (__object->*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    // Handle smart pointers, references and pointers to derived    template<typename _Tp>      _Res      operator()(_Tp& __object _GLIBCXX_COMMA_SHIFTED                 _GLIBCXX_PARAMS_SHIFTED) const      {        return _M_call(__object, &__object _GLIBCXX_COMMA_SHIFTED                       _GLIBCXX_ARGS_SHIFTED);      }  private:    _Functor __pmf;  };template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED         _GLIBCXX_TEMPLATE_PARAMS_SHIFTED>  class _Mem_fn<_Res(_Class::*)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED) const volatile>#if _GLIBCXX_NUM_ARGS == 1  : public unary_function<const volatile _Class*, _Res>#elif _GLIBCXX_NUM_ARGS == 2    : public binary_function<const volatile _Class*, _T1, _Res>#endif  {    typedef _Res (_Class::*_Functor)(_GLIBCXX_TEMPLATE_ARGS_SHIFTED)              const volatile;    template<typename _Tp>      _Res      _M_call(_Tp& __object, const volatile _Class * _GLIBCXX_COMMA_SHIFTED              _GLIBCXX_PARAMS_SHIFTED) const      { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    template<typename _Tp>      _Res      _M_call(_Tp& __ptr, const volatile void * _GLIBCXX_COMMA_SHIFTED              _GLIBCXX_PARAMS_SHIFTED) const      {  return ((*__ptr).*__pmf)(_GLIBCXX_ARGS_SHIFTED); }  public:    typedef _Res result_type;    explicit _Mem_fn(_Functor __pmf) : __pmf(__pmf) { }    // Handle objects    _Res    operator()(const volatile _Class& __object _GLIBCXX_COMMA_SHIFTED               _GLIBCXX_PARAMS_SHIFTED) const    { return (__object.*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    // Handle pointers    _Res    operator()(const volatile _Class* __object _GLIBCXX_COMMA_SHIFTED               _GLIBCXX_PARAMS_SHIFTED) const    { return (__object->*__pmf)(_GLIBCXX_ARGS_SHIFTED); }    // Handle smart pointers, references and pointers to derived    template<typename _Tp>      _Res      operator()(_Tp& __object _GLIBCXX_COMMA_SHIFTED                 _GLIBCXX_PARAMS_SHIFTED) const      {        return _M_call(__object, &__object _GLIBCXX_COMMA_SHIFTED                       _GLIBCXX_ARGS_SHIFTED);      }  private:    _Functor __pmf;  };#endif#if _GLIBCXX_NUM_ARGS > 0namespace placeholders{namespace{   _Placeholder<_GLIBCXX_NUM_ARGS> _GLIBCXX_JOIN(_,_GLIBCXX_NUM_ARGS);}}#endiftemplate<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>class _Bind<_Functor(_GLIBCXX_TEMPLATE_ARGS)>  : public _Weak_result_type<_Functor>{  typedef _Bind __self_type;  _Functor _M_f;  _GLIBCXX_BIND_MEMBERS public:#if _GLIBCXX_NUM_ARGS == 0  explicit#endif  _Bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)    : _M_f(__f) _GLIBCXX_COMMA _GLIBCXX_BIND_MEMBERS_INIT { }#define _GLIBCXX_BIND_REPEAT_HEADER <tr1/bind_iterate.h>#include <tr1/bind_repeat.h>#undef _GLIBCXX_BIND_REPEAT_HEADER};template<typename _Result, typename _Functor         _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>class _Bind_result<_Result, _Functor(_GLIBCXX_TEMPLATE_ARGS)>{  _Functor _M_f;  _GLIBCXX_BIND_MEMBERS public:  typedef _Result result_type;#if _GLIBCXX_NUM_ARGS == 0  explicit#endif  _Bind_result(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)    : _M_f(__f) _GLIBCXX_COMMA _GLIBCXX_BIND_MEMBERS_INIT { }#define _GLIBCXX_BIND_REPEAT_HEADER <tr1/bind_iterate.h>#define _GLIBCXX_BIND_HAS_RESULT_TYPE#include <tr1/bind_repeat.h>#undef _GLIBCXX_BIND_HAS_RESULT_TYPE#undef _GLIBCXX_BIND_REPEAT_HEADER};// Handle arbitrary function objectstemplate<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>inline_Bind<typename _Maybe_wrap_member_pointer<_Functor>::type        (_GLIBCXX_TEMPLATE_ARGS)>bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS){  typedef _Maybe_wrap_member_pointer<_Functor> __maybe_type;  typedef typename __maybe_type::type __functor_type;  typedef _Bind<__functor_type(_GLIBCXX_TEMPLATE_ARGS)> __result_type;  return __result_type(__maybe_type::__do_wrap(__f)                       _GLIBCXX_COMMA _GLIBCXX_ARGS);}template<typename _Result, typename _Functor         _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -