std::make_move_iterator

Header: <iterator>

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.

# Declarations

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

(since C++11) (constexpr since C++17)

# Parameters

# Return value

std::move_iterator(std::move(i))

# Example

#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <string>
#include <vector>
 
auto print = [](const auto rem, const auto& seq)
{
    for (std::cout << rem; const auto& str : seq)
        std::cout << std::quoted(str) << ' ';
    std::cout << '\n';
};
 
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
 
    print("v1 now holds: ", v1);
    print("v2 now holds: ", v2);
    print("original list now holds: ", s);
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 2061C++11make_move_iterator did not convert array arguments to pointersmade to convert

# See also