std::iter_move(std::reverse_iterator)
来自 cppreference.cn
< cpp | iterator | reverse iterator
friend constexpr std::iter_rvalue_reference_t<Iter> iter_move( const std::reverse_iterator& i ) noexcept(/* see below */); |
(自 C++20 起) | |
将解引用调整后的底层迭代器的结果强制转换为其关联的右值引用类型。
等价于 auto tmp = i.base();
return std::ranges::iter_move(--tmp);.
此函数模板对于普通的非限定或限定查找不可见,并且只有当 std::reverse_iterator<Iter> 是参数的关联类时,才能通过实参依赖查找找到。
目录 |
[edit] 参数
i | - | 一个源反向迭代器 |
[edit] 返回值
一个右值引用或一个纯右值临时对象。
[edit] 复杂度
常数。
[edit] 异常
noexcept 规范:
noexcept(
std::is_nothrow_copy_constructible_v<Iter> &&
noexcept(std::ranges::iter_move(--std::declval<Iter&>()))
[edit] 示例
运行此代码
#include <iomanip> #include <iostream> #include <iterator> #include <string> #include <vector> void print(const auto& rem, const auto& v) { std::cout << rem << '[' << size(v) << "] {"; for (char comma[]{0, 0}; const auto& s : v) std::cout << comma << ' ' << std::quoted(s), comma[0] = ','; std::cout << " }\n"; } int main() { std::vector<std::string> p{"Alpha", "Bravo", "Charlie"}, q; print("p", p), print("q", q); using RI = std::reverse_iterator<std::vector<std::string>::iterator>; for (RI iter{p.rbegin()}, rend{p.rend()}; iter != rend; ++iter) q.emplace_back(/* ADL */ iter_move(iter)); print("p", p), print("q", q); }
可能的输出
p[3] { "Alpha", "Bravo", "Charlie" } q[0] { } p[3] { "", "", "" } q[3] { "Charlie", "Bravo", "Alpha" }
[edit] 参见
(C++20) |
将解引用对象的结果强制转换为其关联的右值引用类型 (自定义点对象) |
(C++20) |
将解引用底层迭代器的结果强制转换为其关联的右值引用类型 (函数) |
(C++11) |
将参数转换为 xvalue (函数模板) |
(C++11) |
如果移动构造函数不抛出异常,则将参数转换为 xvalue (函数模板) |
(C++11) |
转发函数参数并使用类型模板参数来保留其值类别 (函数模板) |
(C++20) |
将元素范围移动到新位置 (算法函数对象) |
(C++20) |
以向后顺序将元素范围移动到新位置 (算法函数对象) |