public member function
<iterator>

std::move_iterator::move_iterator

default (1)
move_iterator();
initialization (2)
explicit move_iterator (iterator_type it);
copy (3)
template <class Iter>  move_iterator (const move_iterator<Iter>& m_it);
Construct move_iterator object
Constructs a move_iterator object:

(1) default constructor
Constructs a move iterator that points to no object.
The internal base iterator is value-initialized.
(2) initalization constructor
Constructs a move iterator, copying it as its internal base iterator.
(3) copy / type-cast constructor
Constructs a move iterator from some other move iterator, copying m_it's base iterator.

Parameters

it
An iterator, copied as the base iterator for the object.
Member type iterator_type is the underlying iterator type (the class template parameter: Iterator).
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.

Example

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
// move_iterator 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"};

  typedef std::vector<std::string>::iterator Iter;

  std::copy ( std::move_iterator<Iter>(bar.begin()),
              std::move_iterator<Iter>(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;
}

Output:

foo: one two three


Exception safety

Provides the same level of guarantee as the proper constructor of the base iterator.

See also