std::make_move_iterator
From cppreference.com
| ヘッダ <iterator> で定義 |
||
template< class Iter > std::move_iterator<Iter> make_move_iterator( Iter i ); |
(C++11以降) (C++17 以降 constexpr) |
|
make_move_iterator は、引数 i の型から推論された型で、与えられたイテレータ i の std::move_iterator を構築する便利な関数テンプレートです。
目次 |
[編集] パラメータ
| i | - | ムーブイテレータに変換される入力イテレータ |
[編集] 戻り値
std::move_iterator<Iter>(std::move(i))
[編集] 例
このコードを実行
#include <iomanip> #include <iostream> #include <iterator> #include <list> #include <string> #include <vector> auto print = [](const auto rem, const auto& seq) { for (std::cout << rem; const auto& str : seq) std::cout << std::quoted(str) << ' '; std::cout << '\n'; }; int main() { std::list<std::string> s{"one", "two", "three"}; std::vector<std::string> v1(s.begin(), s.end()); // copy std::vector<std::string> v2(std::make_move_iterator(s.begin()), std::make_move_iterator(s.end())); // move print("v1 now holds: ", v1); print("v2 now holds: ", v2); print("original list now holds: ", s); }
実行結果の例
v1 now holds: "one" "two" "three" v2 now holds: "one" "two" "three" original list now holds: "" "" ""
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 2061 | C++11 | make_move_iterator は配列引数をポインタに変換しませんでした |
変換するようにしました |
[編集] 関連項目
| (C++11) |
間接参照すると右辺値になるイテレータアダプタ (クラステンプレート) |
| (C++11) |
引数をxvalueに変換する (関数テンプレート) |