【小记】copy 与 copy_backward

copy 与 copy_backward

  • copy 从前往后复制,result 参数指向目标容器的 begin 位置
  • copy*backward 从后往前复制,··· end 位置

Possible implementation

template<class InputIt, class OutputIt>
OutputIt copy(InputIt first, InputIt last,
              OutputIt d_first)
{
    for (; first != last; (void)++first, (void)++d_first) {
        *d_first = *first;
    }
    return d_first;
}


template< class BidirIt1, class BidirIt2 >
BidirIt2 copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 d_last)
{
    while (first != last) {
        *(--d_last) = *(--last);
    }
    return d_last;
}
posted @ 2023-01-26 19:27  HelloEricy  阅读(35)  评论(0编辑  收藏  举报