c++标准库的一些自由方法

  c++中标准库中有很多自由方法,比如swap,copy,从这个方面入手深入学习c++。

int casts[10] = {10,21,21,12,121,2,1,12,290,12};
vector<int> vect(10);
copy(casts,casts+10,vect.begin()); // 容器必须足够大,否则会出现未知错误。

  find方法,这个是为了stl容器准备的,这个函数的设计思想并不难,就是一个等于条件的判定,我们自己就可以实现。

template <typename InputIterator, typename T>
InputIterator find(InputIterator first, InputItrator last, const T& value){
   while(first != last && *first != value){
          first++;
      }  
  return first;    
} // 从这个代码就可以看到函数的逻辑,有多个怎么办,找不到怎么办等一系列问题。

  

原文地址:https://www.cnblogs.com/Robin008/p/12232634.html