std::move

来自cppreference.com

 
 
算法库
功能
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
修改序列操作
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
all_of
any_of
none_of
(C++11)
(C++11)
(C++11)
for_each
count
count_if
mismatch
equal
修改序列操作
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
分区操作
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_partitioned(C++11)
partition
partition_copy(C++11)
排序操作(排序的区间)
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
is_sorted(C++11)
is_sorted_until(C++11)
sort
二进制搜索操作(排序的区间)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
设置操作(排序的区间)
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
堆的操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小/最大操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数字操作
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
C库
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <algorithm>
template< class InputIt, class OutputIt >
OutputIt move( InputIt first, InputIt last, OutputIt d_first );
(C++11 起)
移动的范围[first, last)中的元素,到另一个范围开始于d_first。此操作后,移离范围中的元素将包含有效的数值适当类型的,但不一定是相同的值前移到.
Original:
Moves the elements in the range [first, last), to another range beginning at d_first. After this operation the elements in the moved-from range will still contain valid values of the appropriate type, but not necessarily the same values as before the move.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目录

[编辑] 参数

first, last -
的范围内移动的元素
Original:
the range of elements to move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d_first -
的目标范围的开头。如果d_first[first, last)std::move_backward必须使用代替NJ的std ::移动</ span>.
Original:
the beginning of the destination range. If d_first is within [first, last), std::move_backward must be used instead of NJ的std ::移动</ span>. </div>
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
</div></div></div></div>
Type requirements
-
InputIt must meet the requirements of InputIterator.
-
OutputIt must meet the requirements of OutputIterator.

[编辑] 返回值

过去的最后一个元素的元素的输出迭代器的移动(d_first + (last - first)
Original:
Output iterator to the element past the last element moved (d_first + (last - first))
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 复杂性

究竟last - first移动作业.
Original:
Exactly last - first move assignments.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 可能的实现

template<class InputIt, class OutputIt>
OutputIt move(InputIt first, InputIt last, 
                    OutputIt d_first)
{
    while (first != last) {
        *d_first++ = std::move(*first++);
    }
    return d_first;
}

[编辑] 为例

下面的代码将线程从一个容器中的对象(它本身并不是拷贝)到另一个地方。</ P>

Original:
<p>The following code moves thread objects (which themselves are not copyable) from one container to another.</p>
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
</div>

#include <iostream>
#include <vector>
#include <list>
#include <iterator>
#include <thread>
#include <chrono>

void f(int n)
{
    std::this_thread::sleep_for(std::chrono::seconds(n));
    std::cout << "thread " << n << " ended" << '\n';
}

int main()
{
    std::vector<std::thread> v;
    v.emplace_back(f, 1);
    v.emplace_back(f, 2);
    v.emplace_back(f, 3);
    std::list<std::thread> l;
    // copy() would not compile, because std::thread is noncopyable
的std ::移动</ span>(v.begin(), v.end(), std::back_inserter(l));
    for(auto& t : l) t.join();
}
</div>

输出:
Original:
Output:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
thread 1 ended
thread 2 ended
thread 3 ended

[编辑] 另请参阅

(C++11)
某一范围的元素移动到新的位置在向后的顺序
Original:
moves a range of elements to a new location in backwards order
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(函数模板) [edit]

来自“http://zh.cppreference.com/mwiki/index.php?title=cpp/algorithm/move&oldid=27925