gpt4 book ai didi

c++ - std::move_iterator 的迭代器类别

转载 作者:行者123 更新时间:2023-11-30 01:39:05 25 4
gpt4 key购买 nike

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 to T ; if X is a constant iterator, reference is a reference to const T

右值引用是“对T的引用”。因此,他们有资格。如果他们打算排除右值引用,则标准会说“对 T 的左值引用”。

因此,ForwardIterator 返回右值引用是完全有效的。

关于c++ - std::move_iterator 的迭代器类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46505977/

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