_function.h
来自「stl的源码」· C头文件 代码 · 共 434 行 · 第 1/2 页
H
434 行
/* * * Copyright (c) 1994 * Hewlett-Packard Company * * Copyright (c) 1996-1998 * Silicon Graphics Computer Systems, Inc. * * Copyright (c) 1997 * Moscow Center for SPARC Technology * * Copyright (c) 1999 * Boris Fomitchev * * This material is provided "as is", with absolutely no warranty expressed * or implied. Any use is at your own risk. * * Permission to use or copy this software for any purpose is hereby granted * without fee, provided the above notices are retained on all copies. * Permission to modify the code and to distribute modified code is granted, * provided the above notices are retained, and a notice that the code was * modified is included with the above copyright notice. * *//* NOTE: This is an internal header file, included by other STL headers. * You should not attempt to use it directly. */#ifndef _STLP_INTERNAL_FUNCTION_H#define _STLP_INTERNAL_FUNCTION_H#ifndef _STLP_TYPE_TRAITS_H# include <stl/type_traits.h>#endif#ifndef _STLP_INTERNAL_FUNCTION_BASE_H# include <stl/_function_base.h>#endif_STLP_BEGIN_NAMESPACEtemplate <class _Tp>struct not_equal_to : public binary_function<_Tp, _Tp, bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }};template <class _Tp>struct greater : public binary_function<_Tp, _Tp, bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }};template <class _Tp>struct greater_equal : public binary_function<_Tp, _Tp, bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }};template <class _Tp>struct less_equal : public binary_function<_Tp, _Tp, bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }};template <class _Tp>struct divides : public binary_function<_Tp, _Tp, _Tp> { _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }};template <class _Tp>struct modulus : public binary_function<_Tp, _Tp, _Tp> { _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }};template <class _Tp>struct negate : public unary_function<_Tp, _Tp> { _Tp operator()(const _Tp& __x) const { return -__x; }};template <class _Tp>struct logical_and : public binary_function<_Tp, _Tp, bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }};template <class _Tp>struct logical_or : public binary_function<_Tp, _Tp,bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }};template <class _Tp>struct logical_not : public unary_function<_Tp, bool> { bool operator()(const _Tp& __x) const { return !__x; }};#if !defined (_STLP_NO_EXTENSIONS)// identity_element (not part of the C++ standard).template <class _Tp> inline _Tp identity_element(plus<_Tp>) { return _Tp(0); }template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) { return _Tp(1); }#endif#if defined (_STLP_BASE_TYPEDEF_BUG)// this workaround is needed for SunPro 4.0.1// suggested by "Martin Abernethy" <gma@paston.co.uk>:// We have to introduce the XXary_predicate_aux structures in order to// access the argument and return types of predicate functions supplied// as type parameters. SUN C++ 4.0.1 compiler gives errors for template type parameters// of the form 'name1::name2', where name1 is itself a type parameter.template <class _Pair>struct __pair_aux : private _Pair { typedef typename _Pair::first_type first_type; typedef typename _Pair::second_type second_type;};template <class _Operation>struct __unary_fun_aux : private _Operation { typedef typename _Operation::argument_type argument_type; typedef typename _Operation::result_type result_type;};template <class _Operation>struct __binary_fun_aux : private _Operation { typedef typename _Operation::first_argument_type first_argument_type; typedef typename _Operation::second_argument_type second_argument_type; typedef typename _Operation::result_type result_type;};# define __UNARY_ARG(__Operation,__type) __unary_fun_aux<__Operation>::__type# define __BINARY_ARG(__Operation,__type) __binary_fun_aux<__Operation>::__type# define __PAIR_ARG(__Pair,__type) __pair_aux<__Pair>::__type#else# define __UNARY_ARG(__Operation,__type) __Operation::__type# define __BINARY_ARG(__Operation,__type) __Operation::__type# define __PAIR_ARG(__Pair,__type) __Pair::__type#endiftemplate <class _Predicate>class unary_negate : public unary_function<typename __UNARY_ARG(_Predicate, argument_type), bool> { typedef unary_function<typename __UNARY_ARG(_Predicate, argument_type), bool> _Base;public: typedef typename _Base::argument_type argument_type;private: typedef typename __call_traits<argument_type>::const_param_type _ArgParamType;protected: _Predicate _M_pred;public: explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {} bool operator()(_ArgParamType __x) const { return !_M_pred(__x); }};template <class _Predicate>inline unary_negate<_Predicate>not1(const _Predicate& __pred) { return unary_negate<_Predicate>(__pred);}template <class _Predicate>class binary_negate : public binary_function<typename __BINARY_ARG(_Predicate, first_argument_type), typename __BINARY_ARG(_Predicate, second_argument_type), bool> { typedef binary_function<typename __BINARY_ARG(_Predicate, first_argument_type), typename __BINARY_ARG(_Predicate, second_argument_type), bool> _Base;public: typedef typename _Base::first_argument_type first_argument_type; typedef typename _Base::second_argument_type second_argument_type;private: typedef typename __call_traits<first_argument_type>::const_param_type _FstArgParamType; typedef typename __call_traits<second_argument_type>::const_param_type _SndArgParamType;protected: _Predicate _M_pred;public: explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {} bool operator()(_FstArgParamType __x, _SndArgParamType __y) const { return !_M_pred(__x, __y); }};template <class _Predicate>inline binary_negate<_Predicate>not2(const _Predicate& __pred) { return binary_negate<_Predicate>(__pred);}template <class _Operation>class binder1st : public unary_function<typename __BINARY_ARG(_Operation, second_argument_type), typename __BINARY_ARG(_Operation, result_type) > { typedef unary_function<typename __BINARY_ARG(_Operation, second_argument_type), typename __BINARY_ARG(_Operation, result_type) > _Base;public: typedef typename _Base::argument_type argument_type; typedef typename _Base::result_type result_type;private: typedef typename __call_traits<argument_type>::param_type _ArgParamType; typedef typename __call_traits<argument_type>::const_param_type _ConstArgParamType; typedef typename __call_traits<typename _Operation::first_argument_type>::const_param_type _ValueParamType;protected: //op is a Standard name (20.3.6.1), do no make it STLport naming convention compliant. _Operation op; typename _Operation::first_argument_type _M_value;public: binder1st(const _Operation& __x, _ValueParamType __y) : op(__x), _M_value(__y) {} result_type operator()(_ConstArgParamType __x) const { return op(_M_value, __x); } // DR 109 Missing binders for non-const sequence elements result_type operator()(_ArgParamType __x) const { return op(_M_value, __x); }};template <class _Operation, class _Tp>inline binder1st<_Operation>bind1st(const _Operation& __fn, const _Tp& __x) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?