vcl_functional.h
来自「DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.」· C头文件 代码 · 共 590 行 · 第 1/2 页
H
590 行
#ifndef vcl_emulation_functional_h
#define vcl_emulation_functional_h
#define FUNCTION_H // why?
/*
*
* 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.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* 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. Moscow Center for SPARC Technology makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#include <vcl_cstddef.h>
#include "vcl_bool.h"
#if 0
// fsm: these function templates are non-standard, or rather, the
// standard ones live in namespace std::rel_ops.
template <class T>
inline bool operator!=(const T& x, const T& y) { return !(x == y); }
template <class T>
inline bool operator>(const T& x, const T& y) { return y < x; }
template <class T>
inline bool operator<=(const T& x, const T& y) { return !(y < x); }
template <class T>
inline bool operator>=(const T& x, const T& y) { return !(x < y); }
#endif
template <class Arg, class Result>
struct vcl_unary_function
{
typedef Arg argument_type;
typedef Result result_type;
};
template <class Arg1, class Arg2, class Result>
struct vcl_binary_function
{
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};
template <class T>
struct vcl_plus : public vcl_binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const { return x + y; }
};
template <class T>
struct vcl_minus : public vcl_binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const { return x - y; }
};
template <class T>
struct vcl_multiplies : public vcl_binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const { return x * y; }
};
template <class T>
struct vcl_divides : public vcl_binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const { return x / y; }
};
template <class T>
struct vcl_modulus : public vcl_binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const { return x % y; }
};
template <class T>
struct vcl_negate : public vcl_unary_function<T, T>
{
T operator()(const T& x) const { return -x; }
};
template <class T>
struct vcl_equal_to : public vcl_binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const { return x == y; }
};
template <class T>
struct vcl_not_equal_to : public vcl_binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const { return x != y; }
};
template <class T>
struct vcl_greater : public vcl_binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const { return x > y; }
};
template <class T>
struct vcl_less : public vcl_binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const { return x < y; }
};
template <class T>
struct vcl_greater_equal : public vcl_binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const { return x >= y; }
};
template <class T>
struct vcl_less_equal : public vcl_binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const { return x <= y; }
};
template <class T>
struct vcl_logical_and : public vcl_binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const { return x && y; }
};
template <class T>
struct vcl_logical_or : public vcl_binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const { return x || y; }
};
template <class T>
struct vcl_logical_not : public vcl_unary_function<T, bool>
{
bool operator()(const T& x) const { return !x; }
};
# if defined (__STL_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 Operation>
struct vcl__unary_fun_aux : private Operation
{
typedef typename Operation::argument_type argument_type;
typedef typename Operation::result_type result_type;
};
template <class Operation>
struct vcl__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) vcl__unary_fun_aux<Operation>::type
# define __BINARY_ARG(Operation,type) vcl__binary_fun_aux<Operation>::type
# else
# define __UNARY_ARG(Operation,type) Operation::type
# define __BINARY_ARG(Operation,type) Operation::type
# endif
template <class Predicate>
class vcl_unary_negate : public vcl_unary_function<typename __UNARY_ARG(Predicate,argument_type), bool>
{
protected:
Predicate pred;
public:
explicit vcl_unary_negate(const Predicate& x) : pred(x) {}
bool operator()(const argument_type& x) const { return !pred(x); }
};
template <class Predicate>
inline vcl_unary_negate<Predicate> not1(const Predicate& pred)
{
return vcl_unary_negate<Predicate>(pred);
}
template <class Predicate>
class vcl_binary_negate
: public vcl_binary_function<typename __BINARY_ARG(Predicate,first_argument_type),
typename __BINARY_ARG(Predicate,second_argument_type),
bool>
{
protected:
Predicate pred;
public:
explicit vcl_binary_negate(const Predicate& x) : pred(x) {}
bool operator()(const first_argument_type& x,
const second_argument_type& y) const { return !pred(x, y); }
};
template <class Predicate>
inline vcl_binary_negate<Predicate> not2(const Predicate& pred)
{
return vcl_binary_negate<Predicate>(pred);
}
template <class Operation>
class vcl_binder1st :
public vcl_unary_function<typename __BINARY_ARG(Operation,second_argument_type),
typename __BINARY_ARG(Operation,result_type) >
{
protected:
Operation op;
typename __BINARY_ARG(Operation,first_argument_type) value;
public:
vcl_binder1st(const Operation& x,
const typename __BINARY_ARG(Operation,first_argument_type)& y)
: op(x), value(y) {}
typename result_type operator()(const argument_type& x) const { return op(value, x); }
};
template <class Operation, class T>
vcl_binder1st<Operation> bind1st(const Operation& op, const T& x)
{
typedef typename __BINARY_ARG(Operation,first_argument_type) arg_type;
return vcl_binder1st<Operation>(op, arg_type(x));
}
template <class Operation>
class vcl_binder2nd :
public vcl_unary_function<typename __BINARY_ARG(Operation,first_argument_type),
typename __BINARY_ARG(Operation,result_type)>
{
protected:
Operation op;
typename __BINARY_ARG(Operation,second_argument_type) value;
public:
vcl_binder2nd(const Operation& x,
const typename __BINARY_ARG(Operation,second_argument_type)& y)
: op(x), value(y) {}
typename result_type operator()(const argument_type& x) const { return op(x, value); }
};
template <class Operation, class T>
vcl_binder2nd<Operation> bind2nd(const Operation& op, const T& x)
{
typedef typename __BINARY_ARG(Operation,second_argument_type) arg_type;
return vcl_binder2nd<Operation>(op, arg_type(x));
}
template <class Operation1, class Operation2>
class vcl_unary_compose :
public vcl_unary_function<typename __UNARY_ARG(Operation2,argument_type),
typename __UNARY_ARG(Operation1,result_type)>
{
protected:
Operation1 op1;
Operation2 op2;
public:
vcl_unary_compose(const Operation1& x, const Operation2& y) : op1(x), op2(y) {}
typename __UNARY_ARG(Operation1,result_type)
operator()(const typename __UNARY_ARG(Operation2,argument_type)& x) const { return op1(op2(x)); }
};
template <class Operation1, class Operation2>
inline vcl_unary_compose<Operation1, Operation2> compose1(const Operation1& op1,
const Operation2& op2)
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?