在线文档教程
C++
迭代器 | Iterator

std::make_move_iterator

STD:使[医]移动[医]迭代器

Defined in header
template< class Iterator > std::move_iterator<Iterator> make_move_iterator( const Iterator& i (since C++11) (until C++14)
template< class Iterator > std::move_iterator<Iterator> make_move_iterator( Iterator i (since C++14) (until C++17)
template< class Iterator > constexpr std::move_iterator<Iterator> make_move_iterator( Iterator i (since C++17)

make_move_iterator是构造std::move_iterator对于给定的迭代器i从参数类型推导出的类型。

参数

i-input iterator to be converted to move iterator

返回值

std::move_iterator可以从访问的元素中移动到i...

可能的实施

模板<class Iterator>std::Move[医]迭代器<Iterator>制造[医]移动[医]迭代器%28 Iterator I%29{返回STD::Move[医]迭代器<Iterator>%28i%29;}

*。

二次

#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: "" "" ""

二次

另见

move_iterator (C++11)iterator adaptor which dereferences to an rvalue reference (class template)
move (C++11)obtains an rvalue reference (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/iterator/make[医]移动[医]迭代器