gpt4 book ai didi

c++ - 有移动范围的算法吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:22:36 26 4
gpt4 key购买 nike

在 C++98 中,我可以使用 std::copy 算法复制范围。

std::copy(source.begin(), source.end(), destination.begin());

C++0x 中是否有一种算法可以将元素从源移动到目标?还是 std::copy 以某种方式重载以接受右值迭代器之类的东西——甚至有这样的东西吗?

算法可能看起来像这样:

#include <utility>

template<class InputIterator, class OutputIterator>
OutputIterator mooove(InputIterator first, InputIterator last, OutputIterator result)
{
for (; first != last; ++first, ++last) *result = std::move(*first);
return result;
}

最佳答案

好像是在latest draft (参见第 25.3.2 节)。

我有一份 C++03 的硬拷贝,它与 C++98 完全一样(第 25.2.x 节)您可以在其中看到相同的算法(显然没有“移动”)。

关于c++ - 有移动范围的算法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2077919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com