> 文档中心 > 2022年3月28日记:bind适配器

2022年3月28日记:bind适配器

──────────────────────────────────── ┌————————————┐
│▉▉♥♥♥♥♥♥♥♥ 99% │ ♥❤ 鱼沈雁杳天涯路,始信人间别离苦。
└————————————┘
你的感情正在充电中,请稍侯…
────────────────────────────────────
推荐一个 声学 免费公开课程,个人觉得老师讲得不错,分享给大家:[Linux,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK,流媒体,CDN,P2P,K8S,Docker,TCP/IP,协程,DPDK等技术内容,立即学习]
https://ke.qq.com/course/417774?flowToken=1042807
────────────────────────────────────

template<typename Operation,typename T>inline binder2nd<Operation>bind2nd(const & op,const T& x){typedef typename Operation::second_argument_type arg2_type;return binder2nd<Operation>(op,arg2_type(x));template<typename 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:binder2nd(const Operation & x,  const typename Operation::second_argument_type & y)  :op(x),value(y){}typename Operation::result_typeoperatot()(const typename Operation::first_argument_type & x)const{return op(x,value);};}}

bind 新型适配器

double my_divide (double x,double y){return x/y;}struct MyPair{double a.b;double multiply(){return a * b;}};using namespace std::placeholders;auto fn_five=bind(my_didive,10,2);cout<<fn_five()<<endl;auto fn_half=bind(my_divide,_1,2);cout<<fn_half(10)<<endl;auto fn_invert=bind(my_divide,_2,_1);cout<<fn_invert(10,2)<<endl;auto fn_rounding=bind<int>(my_divide,_1,2);cout<<fn_rounding(10,3)<<endl;

reverse_iterator

template<typename Iterator>class reverse_iterator{protected:Iterator current;public:typedef typename iterator_traits<Iterator>::iterator_category iterator)category;typedef typename iterator_traits<Iterator>::value_-type value_type;...typedef Iterator iterator_type;typedef reverse_iterator<Iterator> self; public:explicit reverse_iterator(iterator_type x)::current(x){} reverse_iterator(const self & x):current(x.current){}iterator_type base()const {return current;}reference operator * ()const {Iterator tmp=current;return *00tmp;}pointer operator->()const {return & (operator *());}self & operator++();self & operator--();self operator(difference_type n)const{return self(current-n);}self operator(difference_type n)const{return self(current+n);}};