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

📄 functional

📁 realview22.rar
💻
📖 第 1 页 / 共 2 页
字号:
// -*- C++ -*-
/***************************************************************************
 *
 * functional - global template functions
 *
 * $Id: functional,v 1.1.1.1 2002/01/10 17:38:29 vkorstan Exp $
 *
 ***************************************************************************
 *
 * 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) 1994-2001 Rogue Wave Software, Inc.  All Rights Reserved.
 *
 * This computer software is owned by Rogue Wave Software, Inc. and is
 * protected by U.S. copyright laws and other laws and by international
 * treaties.  This computer software is furnished by Rogue Wave Software,
 * Inc. pursuant to a written license agreement and may be used, copied,
 * transmitted, and stored only in accordance with the terms of such
 * license and with the inclusion of the above copyright notice.  This
 * computer software or any other copies thereof may not be provided or
 * otherwise made available to any other person.
 *
 * U.S. Government Restricted Rights.  This computer software is provided
 * with Restricted Rights.  Use, duplication, or disclosure by the
 * Government is subject to restrictions as set forth in subparagraph (c)
 * (1) (ii) of The Rights in Technical Data and Computer Software clause
 * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
 * Commercial Computer Software--Restricted Rights at 48 CFR 52.227-19,
 * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
 * Flatiron Parkway, Boulder, Colorado 80301 USA.
 *
 **************************************************************************/

#ifndef _RWSTD_FUNCTIONAL_INCLUDED
#define _RWSTD_FUNCTIONAL_INCLUDED

#include <rw/_defs.h>


_RWSTD_NAMESPACE_BEGIN (std)


// 20.3.1 - Base
template <class _Arg, class _Result>
struct unary_function
{
    typedef _Arg    argument_type;
    typedef _Result result_type;
};


#define _RWSTD_UNARY_FUNCTION_TYPES(T, U)                                      \
    typedef _TYPENAME _STD::unary_function<T, U>::argument_type argument_type; \
    typedef _TYPENAME _STD::unary_function<T, U>::result_type   result_type


template <class _Arg1, class _Arg2, class _Result>
struct binary_function
{
    typedef _Arg1   first_argument_type;
    typedef _Arg2   second_argument_type;
    typedef _Result result_type;
};


#define _RWSTD_BINARY_FUNCTION_TYPES(T, U, V)                              \
    typedef _TYPENAME _STD::binary_function<T, U, V>::second_argument_type \
            second_argument_type;                                          \
    typedef _TYPENAME _STD::binary_function<T, U, V>::first_argument_type  \
            first_argument_type;                                           \
    typedef _TYPENAME _STD::binary_function<T, U, V>::result_type          \
            result_type


// 20.3.2 - Arithmetic operations

// 20.3.2, p2
template <class _TypeT>
struct plus : public binary_function<_TypeT, _TypeT, _TypeT>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, _TypeT);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x + __y;
    }
};


// 20.3.2, p3
template <class _TypeT>
struct minus : public binary_function<_TypeT, _TypeT, _TypeT>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, _TypeT);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x - __y;
    }
};


// 20.3.2, p4
template <class _TypeT>
struct multiplies : public binary_function<_TypeT, _TypeT, _TypeT>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, _TypeT);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x * __y;
    }
};


// 20.3.2, p5
template <class _TypeT>
struct divides : public binary_function<_TypeT, _TypeT, _TypeT>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, _TypeT);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x / __y;
    }
};


// 20.3.2, p6
template <class _TypeT>
struct modulus : public binary_function<_TypeT, _TypeT, _TypeT>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, _TypeT);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x % __y;
    }
};


// 20.3.2, p7
template <class _TypeT>
struct negate : public unary_function<_TypeT, _TypeT>
{
    _RWSTD_UNARY_FUNCTION_TYPES (_TypeT, _TypeT);

    result_type operator() (const argument_type &__x) const {
        return -__x;
    }
};


// 20.3.3 - Comparisons


// 20.3.3, p2
template <class _TypeT>
struct equal_to : public binary_function<_TypeT, _TypeT, bool>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, bool);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x == __y;
    }
};


// 20.3.3, p3
template <class _TypeT>
struct not_equal_to : public binary_function<_TypeT, _TypeT, bool>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, bool);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x != __y;
    }
};


// 20.3.3, p4
template <class _TypeT>
struct greater : public binary_function<_TypeT, _TypeT, bool>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, bool);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x > __y;
    }
};


// 20.3.3, p5
template <class _TypeT>
struct less : public binary_function<_TypeT, _TypeT, bool>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, bool);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x < __y;
    }
};


// 20.3.3, p6
template <class _TypeT>
struct greater_equal : public binary_function<_TypeT, _TypeT, bool>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, bool);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x >= __y;
    }
};


// 20.3.3, p7
template <class _TypeT>
struct less_equal : public binary_function<_TypeT, _TypeT, bool>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, bool);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x <= __y;
    }
};


// 20.3.4 - Logical operations

// 20.3.4, p2
template <class _TypeT>
struct logical_and : public binary_function<_TypeT, _TypeT, bool>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, bool);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x && __y;
    }
};


// 20.3.4, p3
template <class _TypeT>
struct logical_or : public binary_function<_TypeT, _TypeT, bool>
{
    _RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _TypeT, bool);

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return __x || __y;
    }
};

// 20.3.4, p4
template <class _TypeT>
struct logical_not : public unary_function<_TypeT, bool>
{
    _RWSTD_UNARY_FUNCTION_TYPES (_TypeT, bool);

    result_type operator() (const _TypeT &__x) const {
        return !__x;
    }
};


// 20.3.5 - Negators

// 20.3.5, p2
template <class _Predicate>
class unary_negate
    : public unary_function<_TYPENAME _Predicate::argument_type, bool>
{
    _Predicate _C_pred;
public:
    _RWSTD_UNARY_FUNCTION_TYPES (_TYPENAME _Predicate::argument_type, bool);

    _EXPLICIT unary_negate (const _Predicate &__pred) : _C_pred (__pred) { }

    result_type operator() (const argument_type &__x) const {
        return !_C_pred (__x);
    }
};


// 20.3.5, p3
template <class _Predicate>
inline unary_negate<_Predicate> not1 (const _Predicate &__pred)
{
    return unary_negate<_Predicate>(__pred);
}


// 20.3.5, p4
template <class _Predicate>
class binary_negate
    : public binary_function<_TYPENAME _Predicate::first_argument_type,
                             _TYPENAME _Predicate::second_argument_type, bool>
{
    _Predicate _C_pred;
public:

    _RWSTD_BINARY_FUNCTION_TYPES (_TYPENAME _Predicate::first_argument_type,
                                  _TYPENAME _Predicate::second_argument_type,
                                  bool);

    _EXPLICIT binary_negate (const _Predicate &__pred) : _C_pred (__pred) { }

    result_type operator() (const first_argument_type  &__x,
                            const second_argument_type &__y) const {
        return !_C_pred (__x, __y);
    }
};


// 20.3.5, p5
template <class _Predicate>
inline binary_negate<_Predicate> not2 (const _Predicate &__pred)
{
    return binary_negate<_Predicate>(__pred);
}


// 20.3.6 - Binders

// 20.3.6.1
template <class _Operation>
struct binder1st
    : public unary_function<_TYPENAME _Operation::second_argument_type,
                            _TYPENAME _Operation::result_type>
{
protected:
    _Operation                                op;
    _TYPENAME _Operation::first_argument_type value;
public:

    _RWSTD_UNARY_FUNCTION_TYPES (_TYPENAME _Operation::second_argument_type,
                                 _TYPENAME _Operation::result_type);

    binder1st (const _Operation                                &__oper,
               const _TYPENAME _Operation::first_argument_type &__x)
        : op (__oper), value (__x) { }

    result_type
    operator() (const argument_type &__y) const {
        return op (value, __y);
    }
};


// 20.3.6.2
template <class _Operation, class _TypeT>
inline binder1st<_Operation>
bind1st (const _Operation &__oper, const _TypeT &__x)
{
    typedef _TYPENAME _Operation::first_argument_type first_argument_type;

    return binder1st<_Operation>(__oper, first_argument_type (__x));
}


// 20.3.6.3
template <class _Operation>
class binder2nd
    : public unary_function<_TYPENAME _Operation::first_argument_type,
                            _TYPENAME _Operation::result_type>
{
protected:
    _Operation                                 op;
    _TYPENAME _Operation::second_argument_type value;
public:

    _RWSTD_UNARY_FUNCTION_TYPES (_TYPENAME _Operation::first_argument_type,
                                 _TYPENAME _Operation::result_type);

    binder2nd (const _Operation                                 &__oper,
               const _TYPENAME _Operation::second_argument_type &__y)
        : op (__oper), value (__y) { }

    result_type
    operator() (const argument_type &__x) const {
        return op (__x, value);
    }
};


// 20.3.6.4
template <class _Operation, class _TypeT>
inline binder2nd<_Operation>
bind2nd (const _Operation &__oper, const _TypeT &__x)
{

⌨️ 快捷键说明

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