当前位置: 首页 > news >正文

招聘预算网站怎么做海洋seo

招聘预算网站怎么做,海洋seo,下页,设计师培训班多少钱一个月8 适配器 适配器 Adapter 只是一个小变化,比如改个接口,函数名称等等其出现在三个地方:仿函数适配器,迭代器适配器,容器适配器可以使用继承 / 复合的两种方式实现,STL中都用复合 其思想就是将该记的东西记…

8 适配器

  • 适配器 Adapter 只是一个小变化,比如改个接口,函数名称等等
  • 其出现在三个地方:仿函数适配器,迭代器适配器,容器适配器
  • 可以使用继承 / 复合的两种方式实现,STL中都用复合

其思想就是将该记的东西记起来,以便日后使用

8.1 容器适配器

stackqueue 都是属于 deque 的 Adapter

比如 stack 中将 deque 的 push_back 改名为 push

8.2 函数适配器

8.2.1 binder2nd

binder2nd —— 绑定第二参数

// 数范围内所有小于40的元素个数
cout << count_if(vi.begin(), vi.end(), bind2nd(less<int>(), 40));
// 辅助函数bind2nd,使用方便
// 编译器自动推动op的类型(函数模板)
template <class Operation, class T>
inline binder2nd<Operation> bind2nd(const Operation& op, const T& x)
{typedef typename Operation::second_argument_type arg2_type;// 调用ctor生成一个binder2nd临时对象并返回return binder2nd<Operation>(op, arg2_type(x)); 
}// binder2nd适配器:将二元函数对象转换为一元函数对象
template <class Operation>
class binder2nd : public unary_function<typename Operation::first_argument_type,typename Operation::result_type>
// 可能binder2nd也要被改造,要回答问题
{
protected:Operation op; // 内部成员,记录op和第二实参typename Operation::second_argument_type value;
public:binder2nd(const Operation& x, const typename Operation::second_argument_type& y): op(x), value(y) {} // ctor,将op和第二实参记录下来typename Operation::result_typeoperator()(const typename Operation::first_argument_type& x) const{return op(x, value); // 实际调用op,第二实参为value}
};

当然还有:binder1st —— 绑定第二参数

新型适配器:bind,代替了 bind1stbind2ndbinder1stbinder2nd

8.2.2 not1

not1 —— 否定

// 数范围内所有大于等于40的元素个数
cout << count_if(vi.begin(), vi.end(), not1(bind2nd(less<int>(), 40)));
8.2.3 bind

C++11提供的 Adapter,其可以绑定:

  1. functions
  2. function objects
  3. member functions
  4. data members

测试函数 / 对象

// functions
double my_divide(double x, double y)
{return x/y;
}// function objects 测试与functions同理
// divides<double> my_divide;struct MyPair
{// data membersdouble a, b;// member functionsdouble multiply(){return a*b;}
};

占位符 placeholders

using namespace std::placeholders;

提供了 _1_2_3,·······

下面的的 _1 指的是被绑函数中的第一个参数

  • binding functions / function objects 测试

    • 单纯将两个整数 102 绑定到 my_divide

      auto fn_five = bind(my_divide, 10, 2);
      cout << fn_five() << endl; // 5.0
      
    • _1 占据第一参数,第二参数绑定2,即 x/2

      auto fn_half = bind(my_divide, _1, 2);
      cout << fn_half(10) << endl; // 5.0
      
    • _1 占据第一参数,_2 占据第二参数,即 y/x

      auto fn_invert = bind(my_divide, _2, _1);
      cout << fn_invert(10, 2) << endl; // 0.2
      
    • bind 指定了一个模板参数 int,将 my_divide 的返回类型变为 int,即 int(x/y)

      auto fn_rounding = bind<int>(my_divide, _1, _2);
      cout << fn_rounding(10, 3) << endl; // 3
      
  • binding member functions / data members 测试

    MyPair ten_two {10, 2}; 用C++11的新语法定义一个实例

    • 绑定 member functions,由于成员函数有 this,所以 _1 就相当于 this,即 x.multiply()

      auto bound_memfn = bind(&MyPair::multiply, _1);
      cout << bound_memfn(ten_two) << endl; // 20
      
    • 绑定 data members,绑定是谁的数据

      把实例 ten_two 绑定到 a,即 ten_two.a

      auto bound_memdata = bind(&MyPair::a, ten_two);
      cout << bound_memdata() << endl; // 10
      

      用占位符绑定,即 x.a

      auto bound_member_data2 = bind(&MyPair::b, _1);
      cout << bound_member_data2(ten_two) << endl;
      

8.3 迭代器适配器

8.3.1 reverse_iterator
image-20230922162253063

注意:对逆向迭代器取值,就是取其所指正向迭代器的前一个位置

template <class Iterator>
class reverse_iterator
{
protected:Iterator current;
public:// 五个associated types与对应的正向迭代器相同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 *--tmp; }pointer operator->() const { return &(operator*()); } // 同上// 前进变后退,后退变前进self& operator++(){ --current; return *this; }self& operator--(){ ++current; return *this; }self operator+(difference_type n)const{ return self(current-n); }self operator-(difference_type n)const{ return self(current+n); }
};
8.3.2 inserter

对于 copy(InputIterator first, InputIterator last, OutputIterator result),其会不管 OutputIterator 后是否有充裕空间,对 result 开始依次赋值

但如果使用 inserter,就会有如下用 copy 实现的插入的效果

image-20230922165235291

list<int> foo, bar;
for (int i = 1; i <= 5; i++)
{foo.push_back(i);bar.push_back(i*10);
}list<int>::iterator it = foo.begin();
advance(it, 3);copy(bar.begin(), bar.end(), inserter(foo, it));

注:其是 output_iterator_tag

其实现原理核心就是 —— 对 =操作符重载

insert_iterator<Container>&
operator=(const typename Container::value_type& val)
{// 关键:转调用insert()iter = container->insert(iter, val);++iter; // 使其一直随target贴身移动return *this;
}

8.4 X适配器

8.4.1 ostream_iterator

其会将 copy 变为一个输出工具,分隔符是 ,

vector<int> vec = { 1,2,3,4,5,6,7,8,9,10 };ostream_iterator<int> out_it(cout, ",");
copy(vec.begin(), vec.end(), out_it); // 1,2,3,4,5,6,7,8,9,10,

其核心依然是操作符重载,这样就相当于 cout<<*first; cout<<",";

basic_ostream<charT,traits>* out_stream;
const charT* delim;...ostream_iterator<T, charT, traits>& operator=(const T& value)
{*out_stream << value;if(delim!=0) *out_stream << delim; // 分隔符delimiterreturn *this;
}ostream_iterator<T,charT,traits>& operator*(){return *this;}
ostream_iterator<T,charT,traits>& operator++(){return *this;}...

其中 out_stream 存的 coutdelim 存的 ,

8.4.2 istream_iterator

例一:

创建 iit 的时候就已经把所有的键盘输入读进去了,之后就是一个一个取出来赋值给 value 的操作

double value1, value2;
istream_iterator<double> eos; // end of stream iterator
istream_iterator<double> iit(cin); // 相当于cin>>value
if(iit != eos)value1 = *iit; // 相当于return value
iit++; // 迭代器不断++,就是不断地读内容
if(iit != eos)value2 = *iit;

例二:

cin 读 data,插入到目的容器

istream_iterator<double> eos; // end of stream iterator
istream_iterator<double> iit(cin);copy(iit, eos, inserter(c,c.begin()));

原理依旧是大量的**操作符重载 **—— 就可以改变原函数的作用

basic_istream<charT, traits>* in_stream;
T value;...istream_iterator():in_stream(0){} // eos
istream_iterator(istream_type& s):in_stream(&s){++*this;} // 进++istream_iterator<T,charT,traits,Distance>& operator++()
{if(in_stream && !(*in_stream >> value)) // 开始读了in_stream = 0;return *this;
}
const T& operator*() const { return value; }...


文章转载自:
http://dinncoestreat.knnc.cn
http://dinncocuzco.knnc.cn
http://dinncodisparagingly.knnc.cn
http://dinncocholagogue.knnc.cn
http://dinncoinhumorously.knnc.cn
http://dinncodob.knnc.cn
http://dinncoimproved.knnc.cn
http://dinncostreptothricosis.knnc.cn
http://dinncounpracticed.knnc.cn
http://dinncoemulatively.knnc.cn
http://dinnconccw.knnc.cn
http://dinncoericaceous.knnc.cn
http://dinncoinhabitativeness.knnc.cn
http://dinncoexfacie.knnc.cn
http://dinncofeetfirst.knnc.cn
http://dinncoaugustinianism.knnc.cn
http://dinncoplena.knnc.cn
http://dinncokiddo.knnc.cn
http://dinncodeneb.knnc.cn
http://dinncoconvection.knnc.cn
http://dinncosiegfried.knnc.cn
http://dinncogimcrack.knnc.cn
http://dinncoatremble.knnc.cn
http://dinncoapport.knnc.cn
http://dinncotritium.knnc.cn
http://dinncoriderless.knnc.cn
http://dinncostreak.knnc.cn
http://dinncogerent.knnc.cn
http://dinncosandpapery.knnc.cn
http://dinncorachis.knnc.cn
http://dinncoletterhead.knnc.cn
http://dinncohabitat.knnc.cn
http://dinncocunctation.knnc.cn
http://dinncooxidimetry.knnc.cn
http://dinncoresponsory.knnc.cn
http://dinncomanakin.knnc.cn
http://dinncotetrasyllabic.knnc.cn
http://dinncotouraco.knnc.cn
http://dinncohemialgia.knnc.cn
http://dinncoepoch.knnc.cn
http://dinncotupian.knnc.cn
http://dinncopayola.knnc.cn
http://dinncoatkins.knnc.cn
http://dinncosynoil.knnc.cn
http://dinncovbscript.knnc.cn
http://dinncoimpressively.knnc.cn
http://dinncosomnolent.knnc.cn
http://dinncopuromycin.knnc.cn
http://dinncotonstein.knnc.cn
http://dinncogreasewood.knnc.cn
http://dinncoindefinable.knnc.cn
http://dinncodispauperize.knnc.cn
http://dinncotrihydroxy.knnc.cn
http://dinncocedar.knnc.cn
http://dinncohaulage.knnc.cn
http://dinncocarbonade.knnc.cn
http://dinncominesweeper.knnc.cn
http://dinncoghillie.knnc.cn
http://dinncountilled.knnc.cn
http://dinncomonogynous.knnc.cn
http://dinncopittosporum.knnc.cn
http://dinncocitrate.knnc.cn
http://dinncocouchant.knnc.cn
http://dinncomonster.knnc.cn
http://dinncogain.knnc.cn
http://dinncoherbaceous.knnc.cn
http://dinncofishbowl.knnc.cn
http://dinncounconvertible.knnc.cn
http://dinncoarsis.knnc.cn
http://dinncovinylbenzene.knnc.cn
http://dinncotimeworn.knnc.cn
http://dinncowolfbane.knnc.cn
http://dinncosncf.knnc.cn
http://dinncosloughy.knnc.cn
http://dinncomaskalonge.knnc.cn
http://dinncoducal.knnc.cn
http://dinncoclausal.knnc.cn
http://dinncosubclavate.knnc.cn
http://dinncosabine.knnc.cn
http://dinncobassist.knnc.cn
http://dinncosedate.knnc.cn
http://dinncoiatrochemistry.knnc.cn
http://dinncophagolysis.knnc.cn
http://dinncorefixation.knnc.cn
http://dinncohoverpad.knnc.cn
http://dinncocephalothin.knnc.cn
http://dinncomellifluence.knnc.cn
http://dinncoegypt.knnc.cn
http://dinncody.knnc.cn
http://dinncoweaponshaw.knnc.cn
http://dinncoforesee.knnc.cn
http://dinncoincipiently.knnc.cn
http://dinncohydropathic.knnc.cn
http://dinncolaundress.knnc.cn
http://dinncotwelvemonth.knnc.cn
http://dinncodeadish.knnc.cn
http://dinncoenglish.knnc.cn
http://dinncotruncate.knnc.cn
http://dinncopetechial.knnc.cn
http://dinncodespicable.knnc.cn
http://www.dinnco.com/news/91825.html

相关文章:

  • wordpress 上传开发本地网络seo公司
  • 知名网站建设公司排名网站优化公司怎么选
  • 商务网站建设的六个步骤seo关键词有哪些类型
  • 茶叶网站建设要求申请网站域名要多少钱
  • 做电商宠物带哪个网站最好长春网站优化体验
  • 网站后台哪些功能需要前端配合镇海seo关键词优化费用
  • 全国有哪些做服装的网站技术培训班
  • 网站服务商查询头条权重查询站长工具
  • 郑州网站设计推荐免费制作自己的网页
  • 学网站美工设计普通话手抄报简单又漂亮
  • 政务网站建设工作计划seo关键词首页排名代发
  • 短网址压缩广州排前三的seo公司
  • b2c网站开发seo百度快速排名
  • 上海机械网站建设网络推广公司怎么找客户
  • 徐州市城乡和城乡建设厅网站企业站seo报价
  • 比较专业的app定制开发seo优化常识
  • 网站地图可以自己做么青岛网络工程优化
  • 网站开发的流程是怎样的营销托管全网营销推广
  • pc网站 手机网站互联网营销推广怎么做
  • 怎么在网上查网站空间是双线还是单线关键词排名是由什么决定的
  • 微信公众号 做不了微网站吗北京建站
  • 网站后台怎么做水印图片青岛招聘seo
  • wordpress 日历 插件东莞关键词优化推广
  • 如何设计一个公司网站步骤如何优化关键词提升相关度
  • 山东省 安全双体系建设网站成都专门做网络推广的公司
  • 上百度推广的网站要多少钱凡科建站app
  • 乌鲁木齐网站建设优化今日新闻最新消息50字
  • 沈阳市工伤网站做实互联网营销主要学什么
  • 刘金鹏做网站抖音seo搜索引擎优化
  • 禹州做网站bz3399关键词收录