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
  • 相关阅读:
    Work harder, smarter 工作需要努力和智慧
    且慢下手(转)
    .net 打包中的参数传递
    sql语句编写技巧
    在安装文件中解压sfx压缩文件
    vs.net编程技巧
    統制勘定(reconciliationaccounts)とは
    ExtJs页面布局总结(转载)
    ext自定义form表单参数为JSON格式getJsonValue:(同时提交多个表单时需要用到)
    oracle截取日期函数
  • 原文地址:https://www.cnblogs.com/freewater/p/2948039.html
Copyright © 2011-2022 走看看