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

📄 functional

📁 symbian上STL模板库的实现
💻
📖 第 1 页 / 共 2 页
字号:
// Functional extensions -*- C++ -*-// Copyright (C) 2002 Free Software Foundation, Inc.//// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,// 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./* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation.  Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose.  It is provided "as is" without express or implied warranty. * * * Copyright (c) 1996 * Silicon Graphics Computer Systems, Inc. * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation.  Silicon Graphics makes no * representations about the suitability of this software for any * purpose.  It is provided "as is" without express or implied warranty. *//** @file ext/functional *  This file is a GNU extension to the Standard C++ Library (possibly *  containing extensions from the HP/SGI STL subset).  You should only *  include this header if you are using GCC 3 or later. */#ifndef _EXT_FUNCTIONAL#define _EXT_FUNCTIONAL 1//#pragma GCC system_header#include <functional>namespace __gnu_cxx{    using std::unary_function;    using std::binary_function;    using std::mem_fun1_t;    using std::const_mem_fun1_t;    using std::mem_fun1_ref_t;    using std::const_mem_fun1_ref_t;    /** The @c identity_element functions are not part of the C++ standard; SGI     *  provided them as an extension.  Its argument is an operation, and its     *  return value is the identity element for that operation.  It is overloaded     *  for addition and multiplication, and you can overload it for your own     *  nefarious operations.     *     *  @addtogroup SGIextensions     *  @{     */    /// An \link SGIextensions SGI extension \endlink.    template <class _Tp> inline _Tp identity_element(std::plus<_Tp>) {        return _Tp(0);    }    /// An \link SGIextensions SGI extension \endlink.    template <class _Tp> inline _Tp identity_element(std::multiplies<_Tp>) {        return _Tp(1);    }    /** @}  */    /** As an extension to the binders, SGI provided composition functors and     *  wrapper functions to aid in their creation.  The @c unary_compose     *  functor is constructed from two functions/functors, @c f and @c g.     *  Calling @c operator() with a single argument @c x returns @c f(g(x)).     *  The function @c compose1 takes the two functions and constructs a     *  @c unary_compose variable for you.     *     *  @c binary_compose is constructed from three functors, @c f, @c g1,     *  and @c g2.  Its @c operator() returns @c f(g1(x),g2(x)).  The function     *  @compose2 takes f, g1, and g2, and constructs the @c binary_compose     *  instance for you.  For example, if @c f returns an int, then     *  \code     *  int answer = (compose2(f,g1,g2))(x);     *  \endcode     *  is equivalent to     *  \code     *  int temp1 = g1(x);     *  int temp2 = g2(x);     *  int answer = f(temp1,temp2);     *  \endcode     *  But the first form is more compact, and can be passed around as a     *  functor to other algorithms.     *     *  @addtogroup SGIextensions     *  @{     */    /// An \link SGIextensions SGI extension \endlink.    template <class _Operation1, class _Operation2>        class unary_compose        : public unary_function<typename _Operation2::argument_type,        typename _Operation1::result_type>    {        protected:            _Operation1 _M_fn1;            _Operation2 _M_fn2;        public:            unary_compose(const _Operation1& __x, const _Operation2& __y)                : _M_fn1(__x), _M_fn2(__y) {}            typename _Operation1::result_type                operator()(const typename _Operation2::argument_type& __x) const {                    return _M_fn1(_M_fn2(__x));                }    };    /// An \link SGIextensions SGI extension \endlink.    template <class _Operation1, class _Operation2>        inline unary_compose<_Operation1,_Operation2>        compose1(const _Operation1& __fn1, const _Operation2& __fn2)        {            return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);        }    /// An \link SGIextensions SGI extension \endlink.    template <class _Operation1, class _Operation2, class _Operation3>        class binary_compose        : public unary_function<typename _Operation2::argument_type,        typename _Operation1::result_type> {            protected:                _Operation1 _M_fn1;                _Operation2 _M_fn2;                _Operation3 _M_fn3;            public:                binary_compose(const _Operation1& __x, const _Operation2& __y,                        const _Operation3& __z)                    : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }                typename _Operation1::result_type                    operator()(const typename _Operation2::argument_type& __x) const {                        return _M_fn1(_M_fn2(__x), _M_fn3(__x));                    }        };    /// An \link SGIextensions SGI extension \endlink.    template <class _Operation1, class _Operation2, class _Operation3>        inline binary_compose<_Operation1, _Operation2, _Operation3>        compose2(const _Operation1& __fn1, const _Operation2& __fn2,                const _Operation3& __fn3)        {            return binary_compose<_Operation1,_Operation2,_Operation3>                (__fn1, __fn2, __fn3);        }    /** @}  */    /** As an extension, SGI provided a functor called @c identity.  When a     *  functor is required but no operations are desired, this can be used as a     *  pass-through.  Its @c operator() returns its argument unchanged.     *     *  @addtogroup SGIextensions     */    template <class _Tp> struct identity : public std::_Identity<_Tp> {};    /** @c select1st and @c select2nd are extensions provided by SGI.  Their     *  @c operator()s     *  take a @c std::pair as an argument, and return either the first member     *  or the second member, respectively.  They can be used (especially with     *  the composition functors) to "strip" data from a sequence before     *  performing the remainder of an algorithm.     *     *  @addtogroup SGIextensions     *  @{     */    /// An \link SGIextensions SGI extension \endlink.    template <class _Pair> struct select1st : public std::_Select1st<_Pair> {};

⌨️ 快捷键说明

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