- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
std::move_iterator
有意义吗?适配器只是继承了模板参数Iterator类型的迭代器类别?
因为前向迭代器要求引用类型为 cv- T&
但是,对于前向迭代器模板,std::move_iterator<It>::reference
将是对迭代器值类型的右值引用(保留引用限定符)。
最佳答案
Because forward iterators requires that the reference type is of cv-T&, however
不正确。标准(C++17、N4659、[forward.iterators]/1.3)表示:
if
X
is a mutable iterator,reference
is a reference toT
; ifX
is a constant iterator,reference
is a reference to constT
右值引用是“对T
的引用”。因此,他们有资格。如果他们打算排除右值引用,则标准会说“对 T
的左值引用”。
因此,ForwardIterator 返回右值引用是完全有效的。
关于c++ - std::move_iterator 的迭代器类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46505977/
我查看了 std::move_iterator 的 STL 源代码并发现它返回 Iterator::value_type&& .当 Iterator::reference 时,这会导致不正确的行为是右
如果我理解正确,a=std::move(b) 将引用 a 绑定(bind)到 b 的地址。而且这个操作之后b指向的内容是不保证的。 move_iterator的实现here有这条线 auto oper
std::move_iterator 有意义吗?适配器只是继承了模板参数Iterator类型的迭代器类别? 因为前向迭代器要求引用类型为 cv- T&但是,对于前向迭代器模板,std::move_it
我有一个 std:vector,其中 MyClass 不能被复制(复制构造函数和赋值构造函数被删除),但可以移动 我想在 for 循环中访问元素,我该怎么做: for(MyClass c : my_v
考虑以下代码: typedef istream_iterator char_itr ; char_itr eos; string ll("some text here"); istringstream
我对此不太确定,所以请解释一下它是如何工作的。 让我们考虑以下代码。 std::vector vec {}; void add (std::vector&& v) { using iter
我是一名优秀的程序员,十分优秀!