首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::make_move_iterator

Defined in header <iterator>

?

?

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;}

*。

二次

代码语言:javascript
复制
#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';
}

二次

可能的产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com