为什么迭代器不可复制? [英] Why are iterators not copyable?
本文介绍了为什么迭代器不可复制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
许多迭代器实现了Clone
trait,但没有一个实现Copy
特质.至少对于像 std:slice::Iter代码>
,克隆
实现 无论如何看起来像一个 memcpy,那么为什么 Copy
也没有实现?
Many iterators implement the Clone
trait, but none of them implement the Copy
trait. At least for simple iterators like std:slice::Iter
, the Clone
implementation looks like a memcpy anyway, so why isn't Copy
also implemented?
推荐答案
来自 PR #20790:
此 PR 还使迭代器不可隐式复制,因为这是库中细微错误的来源.您仍然可以使用 clone()
来显式复制迭代器.
This PR also makes iterator non-implicitly copyable, as this was source of subtle bugs in the libraries. You can still use
clone()
to explictly copy the iterator.
这篇关于为什么迭代器不可复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文