zoukankan      html  css  js  c++  java
  • STL: copy

    copy

    Assigns the values of elements from a source range to a destination range, iterating through the source sequence of elements and assigning them new positions in a forward direction.

    template<class InputIterator, class OutputIterator>
       OutputIterator copy(
          InputIterator _First, 
          InputIterator _Last, 
          OutputIterator _DestBeg
       );

    注,Because the algorithm copies the source elements in order beginning with the first element, the destination range can overlap with the source range provided the _Last position of the source range is not contained in the destination range. copy can be used to shift elements to the left but not the right, unless there is no overlap between the source and destination ranges. To shift to the right any number of positions, use the copy_backward algorithm.

    copy_backward

    Assigns the values of elements from a source range to a destination range, iterating through the source sequence of elements and assigning them new positions in a backward direction.

    template<class BidirectionalIterator1, class BidirectionalIterator2>
       BidirectionalIterator2 copy_backward(
          BidirectionalIterator1 _First, 
          BidirectionalIterator1 _Last,
          BidirectionalIterator2 _DestEnd
       );

    注,Because the algorithm copies the source elements in order beginning with the last element, the destination range can overlap with the source range provided the _First position of the source range is not contained in the destination range. copy_backward can be used to shift elements to the right but not the left, unless there is no overlap between the source and destination ranges. To shift to the left any number of positions, use the copy algorithm.

    注,当源区间和目的区间之间没有重叠时,copy和copy_backward都可以正确工作。但是当_First<=_DestBeg<_Last时,copy由于从左向右复制元素会覆盖源区间,无法正常工作。而这时只能使用copy_backward.但是当_First<=_DestEnd<_Last时,copy_backward由于从右向左复制元素会覆盖源区间,无法正常工作。而这时只能使用copy。

    此外,对于数组可以直接使用速度最快的memcpy和memmove。其中,memmove确保了存在覆盖情况下也可以正确复制。

    copy_if

    Copy all elements in a given range that test true for a specified condition.

    template<class InputIterator, class OutputIterator, class BinaryPredicate>
        OutputIterator copy_if(
            InputIterator _First, 
            InputIterator _Last,
            BinaryPredicate _Comp

    copy_n

    Copies a specified number of elements.

    template<class InputIterator, class Size, class OutputIterator>
        OutputIterator copy_n(
            InputIterator  _First, 
            Size _Count,
            OutputIterator _Dest
  • 相关阅读:
    sql字符串函数(转)
    sqlserver 导入/导出Excel
    SelectSingleNode和SelectNodes区别
    iOS sqlite 的各种操作
    iOS 自定义的对象类型的解档和归档
    开放-封闭原则(OCP)开-闭原则 和 依赖倒转原则,单一职责原则
    iOS UITableView , UITableViewController ,UITableViewCell实现全国各省市遍历,选择相应的地区
    iOS 页面跳转传值,属性传值,代理传值,代码块传值,单例传值,通知传值
    iOS中的事件传递和响应者链条
    iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
  • 原文地址:https://www.cnblogs.com/freewater/p/2948039.html
Copyright © 2011-2022 走看看