函式模板
<iterator>

std::make_move_iterator

template <class Iterator>  move_iterator<Iterator> make_move_iterator (const Iterator& it);
template <class Iterator>  move_iterator<Iterator> make_move_iterator (Iterator it);
構造移動迭代器
it 構造一個 move_iterator 物件,

move_iterator 是一個*迭代器介面卡*,它適配一個迭代器(it),使得解引用它會產生*右值引用*(如同應用了 std::move),而所有其他操作則保持不變。

引數

it
一個迭代器。
Iterator 是任何型別的 輸入迭代器

返回值

一個 move_iterator 等同於 it,但在解引用時會移動。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// make_move_iterator example
#include <iostream>     // std::cout
#include <iterator>     // std::make_move_iterator
#include <vector>       // std::vector
#include <string>       // std::string
#include <algorithm>    // std::copy

int main () {
  std::vector<std::string> foo (3);
  std::vector<std::string> bar {"one","two","three"};

  std::copy ( make_move_iterator(bar.begin()),
              make_move_iterator(bar.end()),
              foo.begin() );

  // bar now contains unspecified values; clear it:
  bar.clear();

  std::cout << "foo:";
  for (std::string& x : foo) std::cout << ' ' << x;
  std::cout << '\n';

  return 0;
}

輸出

foo: one two three


資料競爭

訪問引數。
請注意,返回的物件可用於訪問或修改透過 it 可訪問的元素。

異常安全

提供與複製 it 相同的保證級別。

另見