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_type
operatot()(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);}
};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

屯门山鸡叫我小鸡

加油

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值