std::move_iterator
: cppreference.com
<tbody>
</tbody>
template< class Iter > class move_iterator; |
(C++11) | |
std::move_iterator ( LegacyInputIterator )
iterator_type
|
Iter
| ||||||
iterator_category
|
| ||||||
iterator_concept(C++20) |
std::input_iterator_tag | ||||||
value_type
|
| ||||||
difference_type
|
| ||||||
pointer
|
Iter
| ||||||
reference
|
|
| () | |
| () | |
| () | |
(C++20) |
() |
| () | |
| () |
current (private)
|
base() () |
| () | |
| () | |
| () | |
| 2 () | |
| () | |
(C++20) |
() |
(C++20) |
2 () |
Run this code
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <numeric>
#include <string>
int main()
{
std::vector<std::string> v{"this", "is", "an", "example"};
std::cout << "Old contents of the vector: ";
for (auto& s : v)
std::cout << '"' << s << "\" ";
typedef std::vector<std::string>::iterator iter_t;
std::string concat = std::accumulate(
std::move_iterator<iter_t>(v.begin()),
std::move_iterator<iter_t>(v.end()),
std::string()); // std::make_move_iterator
std::cout << "\nConcatenated as string: " << concat << '\n'
<< "New contents of the vector: ";
for (auto& s : v)
std::cout << '"' << s << "\" ";
std::cout << '\n';
}
:
Old contents of the vector: "this" "is" "an" "example"
Concatenated as string: thisisanexample
New contents of the vector: "" "" "" ""
(C++11) |
std::move_iterator () |
(C++20) |
std::move_iterator () |