我正在阅读 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/