std::iter_move(std::common_iterator)
来自cppreference.com
                    
                                        
                    < cpp | iterator | common iterator
                    
                                                            
                    |   friend std::iter_rvalue_reference_t<I>   std::iter_move( const std::common_iterator& i )  | 
(C++20 起) | |
将解引用底层迭代器的结果转型成其关联右值引用类型。若 i.var 不保有一个 I 对象(即迭代器)则行为未定义。
函数体等价于 return std::ranges::iter_move(std::get<I>(i.var)); 。
此函数对通常无限定或有限定查找不可见,而只能在 std::common_iterator<I,S> 为参数的关联类时由实参依赖查找找到。
参数
| i | - | a source iterator adaptor. | 
返回值
右值引用或纯右值临时量。
复杂度
常数。
示例
运行此代码
#include <iomanip> #include <iostream> #include <iterator> #include <string> #include <vector> void print(auto const& rem, auto const& v) { std::cout << rem << "[" << size(v) << "] { "; for (int o{}; auto const& s : v) std::cout << (o++ == 0 ? "" : ", ") << quoted(s); std::cout << " }\n"; } int main() { std::vector<std::string> p { "Andromeda", "Cassiopeia", "Phoenix" }, q; print("p", p), print("q", q); using CI = std::common_iterator< std::counted_iterator<std::vector<std::string>::iterator>, 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++20)  | 
  将解引用迭代器的结果转型为其关联的右值引用类型  (定制点对象)  | 
|    (C++20)  | 
  转型解引用底层迭代器的结果为其所关联的右值引用类型  (函数)  | 
|    (C++11)  | 
  获得右值引用  (函数模板)  | 
|    (C++11)  | 
  若移动构造函数不抛出则获得右值引用  (函数模板)  | 
|    (C++11)  | 
  转发一个函数实参  (函数模板)  | 
|    (C++20)  | 
  将某一范围的元素移动到一个新的位置   (niebloid)  | 
|    (C++20)  | 
  按从后往前的顺序移动某一范围的元素到新的位置   (niebloid)  |