c++ - copy_backward 和 reverse_copy 之间的区别?

标签 c++ stl generic-programming c++-standard-library

我正在阅读 C++ primer,看到这两个函数似乎具有相同的功能。谁能帮忙告诉我这两者有什么区别?谢谢。

最佳答案

reverse_copy 实际上是将元素倒序放置。

1 2 3 4 5 - > 5 4 3 2 1 

copy_backward 只是向后复制元素,但保留它们的相对顺序。

1 2 3 4 5 

5 先复制,但放在最后一个位置。所以你的输出仍然是:

1 2 3 4 5

http://en.cppreference.com/w/cpp/algorithm/copy_backward

Copies the elements from the range, defined by [first, last), to another range ending at d_last. The elements are copied in reverse order (the last element is copied first), but their relative order is preserved.

http://en.cppreference.com/w/cpp/algorithm/reverse_copy

Copies the elements from the range [first, last) to another range beginning at d_first in such a way that the elements in the new range are in reverse order.

关于c++ - copy_backward 和 reverse_copy 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34049447/

相关文章:

c++ - WMI 和 Windows 服务之间的通信

C++ 引用与返回值

c++ - 将 bind1st 和 bind2nd 与转换一起使用时出现问题

C++ STL算法(列表排序)OpenMP/多线程实现

for-loop - Verilog:有没有办法制作广义加法器(可变宽度/输入数量)?

c++ - 通用类型别名,它们彼此不兼容

c++ - 如何通过引用为 C++0x 传递 Lambda 表达式参数

c++ - cocos2dx 3.3动画实现

c++ - STL/标准 C++ 容器的最佳效率如何?

ios - 使用泛型类型的 Swift 工厂