📄 functional
字号:
typedef _TYPENAME _Operation::second_argument_type second_argument_type;
return binder2nd<_Operation>(__oper, second_argument_type (__x));
}
// 20.3.7 - Adaptors for pointers to functions
// 20.3.7, p2
template <class _Arg, class _Result>
struct pointer_to_unary_function : public unary_function<_Arg, _Result>
{
_RWSTD_UNARY_FUNCTION_TYPES (_Arg, _Result);
_EXPLICIT pointer_to_unary_function (result_type (*__fun)(argument_type))
: _C_fn (__fun) {}
result_type operator() (argument_type __x) const {
return _C_fn (__x);
}
private:
result_type (*_C_fn)(argument_type);
};
// 20.3.7, p3
template <class _Arg, class _Result>
inline pointer_to_unary_function<_Arg, _Result>
ptr_fun (_Result (*__fun)(_Arg))
{
return pointer_to_unary_function<_Arg, _Result>(__fun);
}
// 20.3.7, p4
template <class _Arg1, class _Arg2, class _Result>
struct pointer_to_binary_function
: public binary_function<_Arg1, _Arg2, _Result>
{
_RWSTD_BINARY_FUNCTION_TYPES (_Arg1, _Arg2, _Result);
_EXPLICIT
pointer_to_binary_function (result_type (*__fun)(first_argument_type,
second_argument_type))
: _C_fn (__fun) { }
result_type operator() (first_argument_type __x,
second_argument_type __y) const {
return _C_fn (__x, __y);
}
private:
result_type (*_C_fn)(first_argument_type, second_argument_type);
};
// 20.3.7, p5
template <class _Arg1, class _Arg2, class _Result>
inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
ptr_fun (_Result (*__fun)(_Arg1, _Arg2))
{
return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__fun);
}
// 20.3.8 - Adaptors for pointers to members
// 20.3.8, p2 - adaptor for a non-const member function taking no arguments
// operating on a pointer to a non-const object
template <class _Result, class _TypeT>
struct mem_fun_t: public unary_function<_TypeT*, _Result>
{
_RWSTD_UNARY_FUNCTION_TYPES (_TypeT*, _Result);
_EXPLICIT mem_fun_t (result_type (_TypeT::*__fun)()) : _C_fn (__fun) { }
result_type operator() (argument_type __x) const {
return (__x->*_C_fn)();
}
private:
result_type (_TypeT::*_C_fn)();
};
// 20.3.8, p3 - adaptor for a non-const member function taking one argument
// operating on a pointer to a non-const object
template <class _Result, class _TypeT, class _Arg>
struct mem_fun1_t: public binary_function<_TypeT*, _Arg, _Result>
{
_RWSTD_BINARY_FUNCTION_TYPES (_TypeT*, _Arg, _Result);
_EXPLICIT
mem_fun1_t (result_type (_TypeT::*__fun)(second_argument_type))
: _C_fn (__fun) { }
result_type operator() (first_argument_type __x,
second_argument_type __y) const {
return (__x->*_C_fn)(__y);
}
private:
result_type (_TypeT::*_C_fn)(second_argument_type);
};
// 20.3.8, p4
template <class _Result, class _TypeT>
inline mem_fun_t<_Result, _TypeT> mem_fun (_Result (_TypeT::*__fun)())
{
return mem_fun_t<_Result, _TypeT>(__fun);
}
template <class _Result, class _TypeT, class _Arg>
inline mem_fun1_t<_Result, _TypeT, _Arg>
mem_fun (_Result (_TypeT::*__fun)(_Arg))
{
return mem_fun1_t<_Result, _TypeT, _Arg>(__fun);
}
// 20.3.8, p5 - adaptor for a non-const member function taking no arguments
// operating on a non-const object
template <class _Result, class _TypeT>
struct mem_fun_ref_t: public unary_function<_TypeT, _Result>
{
_RWSTD_UNARY_FUNCTION_TYPES (_TypeT, _Result);
_EXPLICIT mem_fun_ref_t (result_type (_TypeT::*__fun)()) : _C_fn (__fun) { }
result_type operator() (argument_type &__x) const {
return (__x.*_C_fn)();
}
private:
result_type (_TypeT::*_C_fn)();
};
// 20.3.8, p6 - adaptor for a non-const member function taking one argument
// operating on a non-const object
template <class _Result, class _TypeT, class _Arg>
struct mem_fun1_ref_t : public binary_function<_TypeT, _Arg, _Result>
{
_RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _Arg, _Result);
_EXPLICIT
mem_fun1_ref_t (result_type (_TypeT::*__fun)(second_argument_type))
: _C_fn (__fun) { }
result_type operator() (first_argument_type &__x,
second_argument_type __y) const {
return (__x.*_C_fn)(__y);
}
private:
result_type (_TypeT::*_C_fn)(second_argument_type);
};
// 20.3.8, p7
template <class _Result, class _TypeT>
inline mem_fun_ref_t<_Result, _TypeT>
mem_fun_ref(_Result (_TypeT::*__fun)())
{
return mem_fun_ref_t<_Result, _TypeT>(__fun);
}
template <class _Result, class _TypeT, class _Arg>
inline mem_fun1_ref_t<_Result, _TypeT, _Arg>
mem_fun_ref(_Result (_TypeT::*__fun)(_Arg))
{
return mem_fun1_ref_t<_Result, _TypeT, _Arg> (__fun);
}
// 20.3.8, p8 - adaptor for a const member function taking no arguments
// operating on a const object
template <class _Result, class _TypeT>
struct const_mem_fun_t: public unary_function<_TypeT*, _Result>
{
_RWSTD_UNARY_FUNCTION_TYPES (_TypeT*, _Result);
_EXPLICIT const_mem_fun_t (result_type (_TypeT::*__fun)() const)
: _C_fn (__fun) { }
result_type operator() (argument_type __x) const {
return (__x->*_C_fn)();
}
private:
result_type (_TypeT::*_C_fn)() const;
};
// 20.3.8, p9 - adaptor for a const member function taking one argument
// operating on a const object
template <class _Result, class _TypeT, class _Arg>
struct const_mem_fun1_t: public binary_function<_TypeT*, _Arg, _Result>
{
_RWSTD_BINARY_FUNCTION_TYPES (_TypeT*, _Arg, _Result);
_EXPLICIT
const_mem_fun1_t (result_type (_TypeT::*__fun)(second_argument_type) const)
: _C_fn (__fun) { }
result_type operator() (first_argument_type __x,
second_argument_type __y) const {
return (__x->*_C_fn)(__y);
}
private:
result_type (_TypeT::*_C_fn)(second_argument_type) const;
};
// 20.3.8, p10
template <class _Result, class _TypeT>
inline const_mem_fun_t<_Result, _TypeT>
mem_fun (_Result (_TypeT::*__fun)() const)
{
return const_mem_fun_t<_Result, _TypeT>(__fun);
}
template <class _Result, class _TypeT, class _Arg>
inline const_mem_fun1_t<_Result, _TypeT, _Arg>
mem_fun (_Result (_TypeT::*__fun)(_Arg) const)
{
return const_mem_fun1_t<_Result, _TypeT, _Arg>(__fun);
}
// 20.3.8, p11 - adaptor for a const member function taking no arguments
// operating on a const reference to an object
template <class _Result, class _TypeT>
struct const_mem_fun_ref_t: public unary_function<_TypeT, _Result>
{
_RWSTD_UNARY_FUNCTION_TYPES (_TypeT, _Result);
_EXPLICIT const_mem_fun_ref_t (result_type (_TypeT::*__fun)() const)
: _C_fn (__fun) { }
result_type operator() (const argument_type &__x) const {
return (__x.*_C_fn)();
}
private:
result_type (_TypeT::*_C_fn)() const;
};
// 20.3.8, p12 - adaptor for a const member function taking a single argument
// operating on a const reference to an object
template <class _Result, class _TypeT, class _Arg>
class const_mem_fun1_ref_t : public binary_function<_TypeT, _Arg, _Result>
{
_RWSTD_BINARY_FUNCTION_TYPES (_TypeT, _Arg, _Result);
_EXPLICIT
const_mem_fun1_ref_t
(result_type (_TypeT::*__fun)(second_argument_type) const)
: _C_fn (__fun) { }
result_type operator() (const first_argument_type &__x,
second_argument_type __y) const {
return (__x.*_C_fn)(__y);
}
private:
result_type (_TypeT::*_C_fn)(second_argument_type) const;
};
// 20.3.8, p13
template <class _Result, class _TypeT>
inline const_mem_fun_ref_t<_Result, _TypeT>
mem_fun_ref (_Result (_TypeT::*__fun)() const)
{
return const_mem_fun_ref_t<_Result, _TypeT>(__fun);
}
template <class _Result, class _TypeT, class _Arg>
inline const_mem_fun1_ref_t<_Result, _TypeT, _Arg>
mem_fun_ref (_Result (_TypeT::*__fun)(_Arg) const)
{
return const_mem_fun1_ref_t<_Result, _TypeT, _Arg>(__fun);
}
_RWSTD_NAMESPACE_END // std
_RWSTD_NAMESPACE_BEGIN (__rw)
// extension: returns the argument
template <class _TypeT>
struct identity : public _STD::unary_function<_TypeT, _TypeT>
{
_RWSTD_UNARY_FUNCTION_TYPES (_TypeT, _TypeT);
result_type operator() (const argument_type &__val) const {
return __val;
}
};
// extension: returns the result of applying the unary plus operator to arg
template <class _TypeT>
struct unary_plus : public _STD::unary_function<_TypeT, _TypeT>
{
_RWSTD_UNARY_FUNCTION_TYPES (_TypeT, _TypeT);
result_type operator() (const argument_type &__val) const {
return +__val;
}
};
// extension: returns the bitwise complement of the argument
template <class _TypeT>
struct bitwise_complement : public _STD::unary_function<_TypeT, _TypeT>
{
_RWSTD_UNARY_FUNCTION_TYPES (_TypeT, _TypeT);
result_type operator() (const argument_type &__val) const {
return ~__val;
}
};
// extension: returns the bitwise or of the two arguments
template <class _TypeT>
struct bitwise_or : public _STD::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;
}
};
// extension: returns the bitwise and of the two arguments
template <class _TypeT>
struct bitwise_and : public _STD::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;
}
};
// extension: returns the exclusive or (XOR) of the two arguments
template <class _TypeT>
struct exclusive_or : public _STD::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;
}
};
// extension: returns the left argument shifted left by the right argument
template <class _TypeT>
struct shift_left : public _STD::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;
}
};
// extension: returns the left argument shifted right by the right argument
template <class _TypeT>
struct shift_right : public _STD::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;
}
};
_RWSTD_NAMESPACE_END // __rw
#undef _RWSTD_UNARY_FUNCTION_TYPES
#undef _RWSTD_BINARY_FUNCTION_TYPES
#endif // _RWSTD_FUNCTIONAL_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -