C++迭代器庫 - make_move_iterator



描述

它從迭代器構造一個move_iterator物件。

宣告

以下是std::make_move_iterator的宣告。

C++11

template <class Iterator>
  move_iterator<Iterator> make_move_iterator (const Iterator& it);

引數

it − 這是一個迭代器。

返回值

它返回一個等效於it的move_iterator,但在解引用時會進行移動。

異常

如果對it應用一元運算子&時以某種方式丟擲異常,則此函式不會丟擲異常。

時間複雜度

對於隨機訪問迭代器,時間複雜度為常數。

示例

以下示例演示了std::make_move_iterator的使用。

#include <iostream>     
#include <iterator>     
#include <vector>       
#include <string>       
#include <algorithm>    

int main () {
   std::vector<std::string> foo (3);
   std::vector<std::string> bar {"tutorialspont","com","india"};

   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: tutorialspont com india
iterator.htm
廣告