function template
<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);
Construct move iterator
Constructs a move_iterator object from it,

A move_iterator is an iterator adaptor that adapts an iterator (it) so that dereferencing it produces rvalue references (as if std::move was applied), while all other operations behave the same.

Parameters

it
An iterator.
Iterator is any type of input iterator.

Return value

A move_iterator equivalent to it, but that moves on dereferences.

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

Output:

foo: one two three


Data races

Accesses the argument.
Note that the returned object may be used to access or modify elements accessible through it.

Exception safety

Provides the same level of guarantee as copying it.

See also