iter_move(std::common_iterator)
來自 cppreference.com
< cpp | 迭代器 | common_iterator
friend constexpr decltype(auto) iter_move( const std::common_iterator& i ) noexcept(noexcept(ranges::iter_move(std::declval<const I&>())) |
(C++20 起) | |
將底層迭代器解引用的結果轉換為其關聯的右值引用型別。
函式體等價於:return std::ranges::iter_move(std::get<I>(i.var));。
此函式對普通的非限定查詢或限定查詢不可見,只有當std::common_iterator<I, S>是引數的關聯類時,才能透過實參依賴查詢找到它。
如果i.var不持有I
物件(即迭代器),則行為未定義。
目錄 |
[編輯] 引數
i | - | 源迭代器介面卡 |
[編輯] 返回值
一個右值引用或一個純右值臨時量。
[編輯] 複雜度
常數時間。
[編輯] 示例
執行此程式碼
#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++ ? ", " : "") << 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) |
[編輯] 參閱
(C++20) |
將解引用物件的結果轉換為其關聯的右值引用型別 (定製點物件) |
(C++20) |
將底層迭代器解引用的結果轉換為其關聯的右值引用型別 (函式) |
(C++11) |
將引數轉換為亡值 (函式模板) |
(C++11) |
如果移動建構函式不丟擲異常,則將引數轉換為亡值 (函式模板) |
(C++11) |
轉發函式引數並使用型別模板引數來保留其值類別 (函式模板) |
(C++20) |
將一個範圍的元素移動到一個新位置 (演算法函式物件) |
以逆序將一個範圍的元素移動到一個新位置 (演算法函式物件) |