std::make_move_iterator
提供: cppreference.com
ヘッダ <iterator> で定義 | ||
template<class Iter > std::move_iterator<Iter> make_move_iterator(const Iter& i ); | (C++11以上) (C++14未満) | |
template<class Iter > std::move_iterator<Iter> make_move_iterator( Iter i ); | (C++14以上) (C++17未満) | |
template<class Iter > constexprstd::move_iterator<Iter> make_move_iterator( Iter i ); | (C++17以上) | |
make_move_iterator
は指定されたイテレータ i
のための引数型から推定した型を持つ std::move_iterator を構築する便利関数テンプレートです。
目次 |
[編集]引数
i | - | ムーブイテレータに変換される入力イテレータ |
[編集]戻り値
i
を通してアクセスされる要素をムーブするために使用できる std::move_iterator。
[編集]実装例
template<class Iter >constexprstd::move_iterator<Iter> make_move_iterator( Iter i ){returnstd::move_iterator<Iter>(i);} |
[編集]例
Run this code
#include <iostream>#include <list>#include <vector>#include <string>#include <iterator> 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 std::cout<<"v1 now holds: ";for(auto str : v1)std::cout<<"\""<< str <<"\" ";std::cout<<"\nv2 now holds: ";for(auto str : v2)std::cout<<"\""<< str <<"\" ";std::cout<<"\noriginal list now holds: ";for(auto str : s)std::cout<<"\""<< str <<"\" ";std::cout<<'\n';}
出力例:
v1 now holds: "one" "two" "three" v2 now holds: "one" "two" "three" original list now holds: "" "" ""
[編集]関連項目
(C++11) | 右辺値参照を逆参照するイテレータアダプタ (クラステンプレート) |
(C++11) | 右辺値参照を取得します (関数テンプレート) |