Generic Programming and the STL笔记6--Function Object Classes
来源:互联网 发布:实时电脑远程软件 编辑:程序博客网 时间:2024/05/22 04:45
1 Function Object Base Classes
1.1 unary_function
unary_function<Arg, Result>
1.2 binary_function
binary_function<Arg1, Arg2, Result>
2 算术运算
2.1 plus
plus<T>
2.2 minus
minus<T>
2.3 multipies
multiplies<T>
2.4 divides
divides<T>
2.5 modulus
modulus<T>
2.6 negate
negate<T>
3 大小比较
3.1 equal_to
equal_to<T>
3.2 not_equal_to
not_equal_to<T>
3.3 less
less<T>
3.4 greater
greater<T>
3.4 less_equal
less_equal<T>
3.5 greater_equal
greater_equal<T>
4 逻辑运算
4.1 logical_and
logical_and<T>
4.2 logical_or
logical_or<T>
4.3 logical_not
logical_not<T>
5 特殊的Function Objects
5.1 hash
hash<T>
类型只针对char *, const char *, string及内建整数。其它是必须定定义template specialization。
6 Member Function Adapters
用于将member functions当作function objects来调用
mem_fun_t<R, X>
mem_fun_ref_t<R, X>
mem_fun1_t<R, X, A>
mem_fun1_ref_t<R, X, A>
const_mem_fun_t<R, X>
const_mem_fun_ref_t<R, X>
const_mem_fun1_t<R, X, A>
const_mem_fun1_ref_t<R, X, A>
template <class S, class T> mem_fun_t<S,T> mem_fun (S (T::*f)());
template <class S, class T, class A> mem_fun1_t<S,T,A> mem_fun (S (T::*f)(A));
template <class S, class T> const_mem_fun_t<S,T> mem_fun (S (T::*f)() const);
template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun (S (T::*f)(A) const);
template <class S, class T>
mem_fun_ref_t<S,T> mem_fun_ref (S (T::*f)());
template <class S, class T, class A>
mem_fun1_ref_t<S,T,A> mem_fun_ref (S (T::*f)(A));
template <class S, class T>
const_mem_fun_ref_t<S,T> mem_fun_ref (S (T::*f)() const);
template <class S, class T, class A>
const_mem_fun1_ref_t<S,T,A> mem_fun_ref (S (T::*f)(A) const);
用于算法
R mem_fun_t::operator()(X *x) const
会调用x->f(), f()为其构造所接受的参数
R mem_fun_ref_t::operator()(X &x) const
会调用x.f(), f()为其构造所接受的参数
R mem_fun1_t::operator()(X *x, A a) const
会调用x->f(a), f()为其构造所接受的参数
R mem_fun1_ref_t::operator()(X &x, A a) const
会调用x.f(a), f()为其构造所接受的参数
7 其它的Adapters
7.1 bind
binder1st<BinaryFun>
binder2nd<BinaryFun>
bind<class Fn, class ... Args>
如bind(greater<int>(), std::placeholders::_1, 5)
辅助函数
template <class BinaryFun, class T>
binder1st<BinaryFun> bind1st(const BinaryFun &F, const T &c)
template <class BinaryFun, class T>
binder2nd<BinaryFun> bind1st(const BinaryFun &F, const T &c)
用于函数
result_type binder1st::operator()(const argument_type &x) const
即调用F(c, x)
result_type binder1st::operator()(const argument_type &x) const
即调用F(x, c)
7.2 函数指针转换为函数对象
主要用于确定函数类型,当有多个重载函数。把函数指针转换为函数对象。
pointer_to_unary_function<Arg, Result>
pointer_to_binary_function<Arg1, Arg2, Result>
辅助函数
template <class Arg, class Result>
poiter_to_unary_function<Arg, Result> ptr_fun(Result (*x)(Arg))
template <class Arg1, class Arg2, class Result>
poiter_to_binary_function<Arg1, Arg2, Result> ptr_fun(Result (*x)(Arg1, Arg2))
7.3 逻辑负值
unary_negate<UnaryPredicate>
binary_negate<BinaryPredicate>
辅助函数
template <class Predicate>
unary_negate<Predicate> not1(const Predicate &p)
template <class BinaryPredicate>
binary_negate<BinaryPredicate> not2(const BinaryPredicate &p)
1.1 unary_function
unary_function<Arg, Result>
1.2 binary_function
binary_function<Arg1, Arg2, Result>
2 算术运算
2.1 plus
plus<T>
2.2 minus
minus<T>
2.3 multipies
multiplies<T>
2.4 divides
divides<T>
2.5 modulus
modulus<T>
2.6 negate
negate<T>
3 大小比较
3.1 equal_to
equal_to<T>
3.2 not_equal_to
not_equal_to<T>
3.3 less
less<T>
3.4 greater
greater<T>
3.4 less_equal
less_equal<T>
3.5 greater_equal
greater_equal<T>
4 逻辑运算
4.1 logical_and
logical_and<T>
4.2 logical_or
logical_or<T>
4.3 logical_not
logical_not<T>
5 特殊的Function Objects
5.1 hash
hash<T>
类型只针对char *, const char *, string及内建整数。其它是必须定定义template specialization。
6 Member Function Adapters
用于将member functions当作function objects来调用
mem_fun_t<R, X>
mem_fun_ref_t<R, X>
mem_fun1_t<R, X, A>
mem_fun1_ref_t<R, X, A>
const_mem_fun_t<R, X>
const_mem_fun_ref_t<R, X>
const_mem_fun1_t<R, X, A>
const_mem_fun1_ref_t<R, X, A>
template <class S, class T> mem_fun_t<S,T> mem_fun (S (T::*f)());
template <class S, class T, class A> mem_fun1_t<S,T,A> mem_fun (S (T::*f)(A));
template <class S, class T> const_mem_fun_t<S,T> mem_fun (S (T::*f)() const);
template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun (S (T::*f)(A) const);
template <class S, class T>
mem_fun_ref_t<S,T> mem_fun_ref (S (T::*f)());
template <class S, class T, class A>
mem_fun1_ref_t<S,T,A> mem_fun_ref (S (T::*f)(A));
template <class S, class T>
const_mem_fun_ref_t<S,T> mem_fun_ref (S (T::*f)() const);
template <class S, class T, class A>
const_mem_fun1_ref_t<S,T,A> mem_fun_ref (S (T::*f)(A) const);
用于算法
R mem_fun_t::operator()(X *x) const
会调用x->f(), f()为其构造所接受的参数
R mem_fun_ref_t::operator()(X &x) const
会调用x.f(), f()为其构造所接受的参数
R mem_fun1_t::operator()(X *x, A a) const
会调用x->f(a), f()为其构造所接受的参数
R mem_fun1_ref_t::operator()(X &x, A a) const
会调用x.f(a), f()为其构造所接受的参数
7 其它的Adapters
7.1 bind
binder1st<BinaryFun>
binder2nd<BinaryFun>
bind<class Fn, class ... Args>
如bind(greater<int>(), std::placeholders::_1, 5)
辅助函数
template <class BinaryFun, class T>
binder1st<BinaryFun> bind1st(const BinaryFun &F, const T &c)
template <class BinaryFun, class T>
binder2nd<BinaryFun> bind1st(const BinaryFun &F, const T &c)
用于函数
result_type binder1st::operator()(const argument_type &x) const
即调用F(c, x)
result_type binder1st::operator()(const argument_type &x) const
即调用F(x, c)
7.2 函数指针转换为函数对象
主要用于确定函数类型,当有多个重载函数。把函数指针转换为函数对象。
pointer_to_unary_function<Arg, Result>
pointer_to_binary_function<Arg1, Arg2, Result>
辅助函数
template <class Arg, class Result>
poiter_to_unary_function<Arg, Result> ptr_fun(Result (*x)(Arg))
template <class Arg1, class Arg2, class Result>
poiter_to_binary_function<Arg1, Arg2, Result> ptr_fun(Result (*x)(Arg1, Arg2))
7.3 逻辑负值
unary_negate<UnaryPredicate>
binary_negate<BinaryPredicate>
辅助函数
template <class Predicate>
unary_negate<Predicate> not1(const Predicate &p)
template <class BinaryPredicate>
binary_negate<BinaryPredicate> not2(const BinaryPredicate &p)
0 0
- Generic Programming and the STL笔记6--Function Object Classes
- Generic Programming and the STL笔记5--Iterator Classes
- Generic Programming and the STL笔记1
- Generic Programming and the STL笔记4--排序和查找
- Generic Programming and the STL笔记7--容器类
- Generic Programming and the STL笔记2--“不改变操作对象之内容”的算法
- Generic Programming and the STL笔记3--“会改变操作对象之内容”的算法
- 《Generic Programming and the STL》读书笔记
- Chapter 9 Templates. Generic Programming. and STL
- 读书摘要─Generic Programming and STL
- 《C++ Primer》 Part IV(Object-Oriented and Generic Programming)
- Part1:A Brief Study of Classes and Object-oriented Programming.
- Templates and Generic Programming
- Multi-Language Programming : Entity Object Inheritance And Function Overloading_3
- Programming in scala学习笔记(三)Classes and Objects
- 16-Templates and Generic Programming
- LUA学习笔记2-Iterators and the Generic for
- Effective STL笔记(1)-Programming with the STL
- 国外7岁小孩总结活到百岁25件事
- Socket通信原理探讨(C++为例)
- Android中Parcelable接口用法
- Android通过adb启动应用
- 四、文本和输出
- Generic Programming and the STL笔记6--Function Object Classes
- DBUtils学习总结
- 【原创】C语言处理文件数据(5)
- Android 单个Activity后台运行,及Activity隐藏但是不调用OnDestory方法
- "Command /usr/bin/codesign failed with exit code 1",真机调试出错解决办法
- iOS 实现一个类似电商购物车界面示例
- 浅谈java 中构建可执行 jar 包的几种方式
- 这两年的工作总结
- seven叶项目总结02