< cpp‎ | iterator
Iterator library
Iterator concepts
Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
Iterator adaptors
Stream iterators
Iterator customization points
Iterator operations
Range access
Defined in header <iterator>
template< class Iter >
std::move_iterator<Iter> make_move_iterator( Iter i );
(since C++11)
(until C++17)
template< class Iter >
constexpr std::move_iterator<Iter> make_move_iterator( Iter i );
(since C++17)

make_move_iterator is a convenience function template that constructs a std::move_iterator for the given iterator i with the type deduced from the type of the argument.


[edit] Parameters

i - input iterator to be converted to move iterator

[edit] Return value

A std::move_iterator which can be used to move from the elements accessed through i

[edit] Possible implementation

template< class Iter >
constexpr std::move_iterator<Iter> make_move_iterator( Iter i )
    return std::move_iterator<Iter>(std::move(i));

[edit] Example

#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <iterator>
int main()
    std::list<std::string> s{"one", "two", "three"};
    std::vector<std::string> v1(s.begin(), s.end()); // copy
    std::vector<std::string> v2(std::make_move_iterator(s.begin()),
                                std::make_move_iterator(s.end())); // move
    std::cout << "v1 now holds: ";
    for (auto str : v1)
            std::cout << "\"" << str << "\" ";
    std::cout << "\nv2 now holds: ";
    for (auto str : v2)
            std::cout << "\"" << str << "\" ";
    std::cout << "\noriginal list now holds: ";
    for (auto str : s)
            std::cout << "\"" << str << "\" ";
    std::cout << '\n';

Possible output:

v1 now holds: "one" "two" "three"
v2 now holds: "one" "two" "three"
original list now holds: "" "" ""

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 2061 C++11 make_move_iterator did not convert array arguments to pointers made to convert

[edit] See also

iterator adaptor which dereferences to an rvalue reference
(class template) [edit]
obtains an rvalue reference
(function template) [edit]