std::make_move_iterator(3)
π NAME π
std::make_move_iterator(3) β bestie, welcome to the std::make_move_iterator page from the C++ Standard Libary manual, and it's literally here to hand you the move-iterator glow-up β¨
π¦ Synopsis π¦
okay so first things first: it's defined in header <iterator> π«Ά
Defined in header <iterator>
template< class Iter >
(since C++11)
std::move_iterator<Iter> make_move_iterator( Iter i );
(until C++17)
template< class Iter >
(since C++17)
constexpr std::move_iterator<Iter> make_move_iterator( Iter i );
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. no cap, that's the whole serve π
π Parameters π
iβ input iterator to be converted to move iterator
πΈ Return value πΈ
A std::move_iterator which can be used to move from the elements accessed through i. she's giving access-with-a-move-vibe, periodt.
β¨ Possible implementation β¨
here's the possible-implementation mood board, and yes the code is exact:
template<class Iter>
constexpr std::move_iterator<Iter> make_move_iterator(Iter i)
{
return std::move_iterator<Iter>(std::move(i));
}
π Example π
// Run this code π that's what the page says right before the code, so we're keeping it.
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <string>
#include <vector>
auto print = [](auto const rem, auto const& seq)
{
for (std::cout << rem; auto const& 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);
}
π Possible output π
v1 now holds: "one" "two" "three"
v2 now holds: "one" "two" "three"
original list now holds: "" "" ""
π«Ά Defect reports π«Ά
okay so the following behavior-changing defect reports were applied retroactively to previously published C++ standards:
LWG 2061β applied to C++11. behavior as published:make_move_iteratordid not convert array arguments to pointers. correct behavior: made to convert.
π See also π
move_iteratorβ iterator adaptor which dereferences to an rvalue; since C++11, class template.moveβ obtains an rvalue reference; since C++11, function template.
source: http://cppreference.com Β· version/date: 2024.06.10 β mwah, bestie π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms