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
  • 相关阅读:
    JQuery 获取touchstart,touchmove,touchend 坐标
    js获取可视区大小和页面大小的兼容性写法
    Asp.net MVC4.0自定义Html辅助方法
    无废话版本-Asp.net MVC4.0 Rasor的基本用法
    IE浏览器 下面的文本框,获得焦点后无法输入内容
    C# Log4Net配置
    C#中 ? 和?? 的用法
    工作中的一些问题总结
    JsRender系列-11
    JsRender系列demo-10
  • 原文地址:https://www.cnblogs.com/freewater/p/2948039.html
Copyright © 2011-2022 走看看