📄 functional
字号:
// functional stl/clr header
#ifndef _CLI_FUNCTIONAL_
#define _CLI_FUNCTIONAL_
#include <cliext/xutility>
namespace cliext {
//
// GENERICS DELEGATES
//
// GENERIC DELEGATE unary_delegate
//
generic<typename TArg,
typename TResult>
delegate TResult unary_delegate(TArg);
// GENERIC DELEGATE unary_delegate_noreturn
//
generic<typename TArg>
delegate void unary_delegate_noreturn(TArg);
//
// GENERIC DELEGATE binary_delegate
//
generic<typename TArg1,
typename TArg2,
typename TResult>
delegate TResult binary_delegate(TArg1, TArg2);
//
// GENERIC DELEGATE binary_delegate_noreturn
//
generic<typename TArg1,
typename TArg2>
delegate void binary_delegate_noreturn(TArg1, TArg2);
//
// TEMPLATE REF FUNCTORS
//
//
// TEMPLATE REF unary_function
//
template<typename _Arg_t,
typename _Result_t>
ref class unary_function
{ // defines typedefs for a unary function
public:
typedef _Arg_t argument_type;
typedef _Result_t result_type;
};
//
// TEMPLATE REF binary_function
//
template<typename _Arg1_t,
typename _Arg2_t,
typename _Result_t>
ref class binary_function
{ // defines typedefs for a binary function
public:
typedef _Arg1_t first_argument_type;
typedef _Arg2_t second_argument_type;
typedef _Result_t result_type;
};
//
// TEMPLATE REF CLASS ref_logical_not
//
template<typename _Arg_t>
ref class ref_logical_not
: public unary_function<_Arg_t, bool>
{ // generic functor for logical_not
public:
static result_type function(argument_type _Left)
{ // do the operation
return (!_Left);
}
};
//
// TEMPLATE REF CLASS ref_negate
//
template<typename _Arg_t>
ref class ref_negate
: public unary_function<_Arg_t, _Arg_t>
{ // generic functor for negate
public:
static result_type function(argument_type _Left)
{ // do the operation
return (-_Left);
}
};
//
// TEMPLATE REF CLASS ref_plus
//
template<typename _Arg_t>
ref class ref_plus
: public binary_function<_Arg_t, _Arg_t, _Arg_t>
{ // generic functor for plus
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left + _Right);
}
};
//
// TEMPLATE REF CLASS ref_minus
//
template<typename _Arg_t>
ref class ref_minus
: public binary_function<_Arg_t, _Arg_t, _Arg_t>
{ // generic functor for minus
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left - _Right);
}
};
//
// TEMPLATE REF CLASS ref_multiplies
//
template<typename _Arg_t>
ref class ref_multiplies
: public binary_function<_Arg_t, _Arg_t, _Arg_t>
{ // generic functor for multiplies
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left * _Right);
}
};
//
// TEMPLATE REF CLASS ref_divides
//
template<typename _Arg_t>
ref class ref_divides
: public binary_function<_Arg_t, _Arg_t, _Arg_t>
{ // generic functor for divides
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left / _Right);
}
};
//
// TEMPLATE REF CLASS ref_modulus
//
template<typename _Arg_t>
ref class ref_modulus
: public binary_function<_Arg_t, _Arg_t, _Arg_t>
{ // generic functor for modulus
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left % _Right);
}
};
//
// TEMPLATE REF CLASS ref_equal_to
//
template<typename _Arg_t>
ref class ref_equal_to
: public binary_function<_Arg_t, _Arg_t, bool>
{ // generic functor for equal_to
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left == _Right);
}
};
//
// TEMPLATE REF CLASS ref_not_equal_to
//
template<typename _Arg_t>
ref class ref_not_equal_to
: public binary_function<_Arg_t, _Arg_t, bool>
{ // generic functor for not_equal_to
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left != _Right);
}
};
//
// TEMPLATE REF CLASS ref_less
//
template<typename _Arg_t>
ref class ref_less
: public binary_function<_Arg_t, _Arg_t, bool>
{ // generic functor for less
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left < _Right);
}
};
//
// TEMPLATE REF CLASS ref_greater_equal
//
template<typename _Arg_t>
ref class ref_greater_equal
: public binary_function<_Arg_t, _Arg_t, bool>
{ // generic functor for greater_equal
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left >= _Right);
}
};
//
// TEMPLATE REF CLASS ref_greater
//
template<typename _Arg_t>
ref class ref_greater
: public binary_function<_Arg_t, _Arg_t, bool>
{ // generic functor for greater
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left > _Right);
}
};
//
// TEMPLATE REF CLASS ref_less_equal
//
template<typename _Arg_t>
ref class ref_less_equal
: public binary_function<_Arg_t, _Arg_t, bool>
{ // generic functor for less_equal
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left <= _Right);
}
};
//
// TEMPLATE REF CLASS ref_logical_and
//
template<typename _Arg_t>
ref class ref_logical_and
: public binary_function<_Arg_t, _Arg_t, bool>
{ // generic functor for logical_and
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left && _Right);
}
};
//
// TEMPLATE REF CLASS ref_logical_or
//
template<typename _Arg_t>
ref class ref_logical_or
: public binary_function<_Arg_t, _Arg_t, bool>
{ // generic functor for logical_or
public:
static result_type function(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (_Left || _Right);
}
};
//
// TEMPLATE FUNCTORS
//
//
// TEMPLATE CLASS _Unary_fun
//
template<typename _Ref_t>
ref class _Unary_fun
{ // functor for unary function
public:
typedef _Ref_t ref_type;
typedef typename ref_type::argument_type argument_type;
typedef typename ref_type::result_type result_type;
typedef _STLCLR UnaryDelegate<argument_type, result_type>
delegate_type;
result_type operator()(argument_type _Left)
{ // do the operation
return (ref_type::function(_Left));
}
operator delegate_type^()
{ // convert function to delegate
return (gcnew delegate_type(&ref_type::function));
}
};
//
// TEMPLATE CLASS _Unary_fun_noreturn
//
template<typename _Ref_t>
ref class _Unary_fun_noreturn
{ // functor for unary function returning void
public:
typedef _Ref_t ref_type;
typedef typename ref_type::argument_type argument_type;
typedef void result_type;
typedef unary_delegate_noreturn<argument_type>
delegate_type;
result_type operator()(argument_type _Left)
{ // do the operation
return (ref_type::function(_Left));
}
operator delegate_type^()
{ // convert function to delegate
return (gcnew delegate_type(&ref_type::function));
}
};
//
// TEMPLATE CLASS _Binary_fun
//
template<typename _Ref_t>
ref class _Binary_fun
{ // functor for binary function
public:
typedef _Ref_t ref_type;
typedef typename ref_type::first_argument_type first_argument_type;
typedef typename ref_type::second_argument_type second_argument_type;
typedef typename ref_type::result_type result_type;
typedef _STLCLR BinaryDelegate<
first_argument_type, second_argument_type, result_type>
delegate_type;
result_type operator()(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (ref_type::function(_Left, _Right));
}
operator delegate_type^()
{ // convert function to delegate
return (gcnew delegate_type(&ref_type::function));
}
};
//
// TEMPLATE CLASS _Binary_fun_noreturn
//
template<typename _Ref_t>
ref class _Binary_fun_noreturn
{ // functor for binary function returning void
public:
typedef _Ref_t ref_type;
typedef typename ref_type::first_argument_type first_argument_type;
typedef typename ref_type::second_argument_type second_argument_type;
typedef void result_type;
typedef binary_delegate_noreturn<
first_argument_type, second_argument_type>
delegate_type;
result_type operator()(first_argument_type _Left,
second_argument_type _Right)
{ // do the operation
return (ref_type::function(_Left, _Right));
}
operator delegate_type^()
{ // convert function to delegate
return (gcnew delegate_type(&ref_type::function));
}
};
//
// TEMPLATE CLASS logical_not
//
template<typename _Arg_t>
ref class logical_not
: public _Unary_fun< ref_logical_not<_Arg_t> >
{ // functor for logical_not
public:
typedef logical_not _Mytype_t;
logical_not()
{ // default constructor
}
logical_not(logical_not%)
{ // copy constructor
}
};
//
// TEMPLATE CLASS negate
//
template<typename _Arg_t>
ref class negate
: public _Unary_fun< ref_negate<_Arg_t> >
{ // functor for negate
public:
typedef negate _Mytype_t;
negate()
{ // default constructor
}
negate(negate%)
{ // copy constructor
}
};
//
// TEMPLATE CLASS plus
//
template<typename _Arg_t>
ref class plus
: public _Binary_fun< ref_plus<_Arg_t> >
{ // functor for plus
public:
typedef plus _Mytype_t;
plus()
{ // default constructor
}
plus(plus%)
{ // copy constructor
}
};
//
// TEMPLATE CLASS minus
//
template<typename _Arg_t>
ref class minus
: public _Binary_fun< ref_minus<_Arg_t> >
{ // functor for minus
public:
typedef minus _Mytype_t;
minus()
{ // default constructor
}
minus(minus%)
{ // copy constructor
}
};
//
// TEMPLATE CLASS multiplies
//
template<typename _Arg_t>
ref class multiplies
: public _Binary_fun< ref_multiplies<_Arg_t> >
{ // functor for multiplies
public:
typedef multiplies _Mytype_t;
multiplies()
{ // default constructor
}
multiplies(multiplies%)
{ // copy constructor
}
};
//
// TEMPLATE CLASS divides
//
template<typename _Arg_t>
ref class divides
: public _Binary_fun< ref_divides<_Arg_t> >
{ // functor for divides
public:
typedef divides _Mytype_t;
divides()
{ // default constructor
}
divides(divides%)
{ // copy constructor
}
};
//
// TEMPLATE CLASS modulus
//
template<typename _Arg_t>
ref class modulus
: public _Binary_fun< ref_modulus<_Arg_t> >
{ // functor for modulus
public:
typedef modulus _Mytype_t;
modulus()
{ // default constructor
}
modulus(modulus%)
{ // copy constructor
}
};
//
// TEMPLATE CLASS equal_to
//
template<typename _Arg_t>
ref class equal_to
: public _Binary_fun< ref_equal_to<_Arg_t> >
{ // functor for equal_to
public:
typedef equal_to _Mytype_t;
equal_to()
{ // default constructor
}
equal_to(equal_to%)
{ // copy constructor
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -