public member function
<iterator>

std::move_iterator::operator=

template <class Iter>  move_iterator& operator= (const move_iterator<Iter>& m_it);
Assign iterator
Assigns m_it's base iterator to the object's base iterator, replacing its current value.

参数

m_it
An iterator of a move_iterator type, whose base iterator is copied.
Iter shall be a type convertible to the type of the base iterator.

返回值

*this

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// move_iterator::operator= example
#include <iostream>     // std::cout
#include <iterator>     // std::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::move_iterator<std::vector<std::string>::iterator> from,until;

  // move_iterator assignments:
  from = bar.begin();
  until = bar.end();

  std::copy ( from, until, foo.begin() );

  // bar 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


数据竞争

修改对象。
返回的迭代器可用于访问或修改指向的元素。

异常安全

Provides the same level of guarantee as the copy-assignment of the base iterator.

另见