iter_move(std::common_iterator)
来自cppreference.com
| |
(C++20 起) | |
将解引用底层迭代器的结果转型成它关联的右值引用类型。
等价于 return std::ranges::iter_move(std::get<I>(i.var ));。
|
如果 |
(C++26 前) |
|
如果 |
(C++26 起) |
此函数对常规的无限定或有限定查找不可见,而只能在 std::common_iterator<I, S> 为实参的关联类时由实参依赖查找找到。
参数
| i | - | 作为源的迭代器适配器 |
返回值
右值引用或纯右值临时量。
复杂度
常数。
示例
运行此代码
#include <iomanip>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
void print(const auto& rem, const auto& v)
{
std::cout << rem << '[' << size(v) << "] { ";
for (int o{}; auto const& s : v)
std::cout << (o++ ? ", " : "") << std::quoted(s);
std::cout << " }\n";
}
int main()
{
std::vector<std::string> p{"Andromeda", "Cassiopeia", "Phoenix"}, q;
print("p", p);
print("q", q);
using CTI = std::counted_iterator<std::vector<std::string>::iterator>;
using CI = std::common_iterator<CTI, std::default_sentinel_t>;
CI last{std::default_sentinel};
for (CI first{{p.begin(), 2}}; first != last; ++first)
q.emplace_back(/* ADL */ iter_move(first));
print("p", p);
print("q", q);
}
可能的输出:
p[3] { "Andromeda", "Cassiopeia", "Phoenix" }
q[0] { }
p[3] { "", "", "Phoenix" }
q[2] { "Andromeda", "Cassiopeia" }
缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
| 缺陷报告 | 应用于 | 出版时的行为 | 正确行为 |
|---|---|---|---|
| LWG 3953 | C++20 | 返回类型是 std::iter_rvalue_reference_t<I>
|
改为 decltype(auto)
|
