GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing cpprefjp.github.io — std::move_iterator - cpprefjp C++日本語リファレンス class template <iterator> std::move_iterator(C++11)概要
要件
メンバ関数
メンバ型
非メンバ関数
|
| 名前 | 説明 | 対応バージョン |
|---|---|---|
operator== |
等値比較 | C++20 |
operator!= |
非等値比較(==により使用可能) |
C++20 |
operator- |
move_iteratorと終端との差を求める |
C++20 |
#include <iostream>
#include <vector>
#include <memory>
#include <algorithm>
#include <iterator>
int main()
{
std::vector<std::unique_ptr<int>> v;
for (int i = 0; i < 5; ++i)
v.emplace_back(new int(i));
std::vector<std::unique_ptr<int>> v2;
v2.assign(std::make_move_iterator(v.begin()),
std::make_move_iterator(v.end()));
std::for_each(v2.begin(), v2.end(),
[](const std::unique_ptr<int>& v) { std::cout << *v << std::endl; });
}
0
1
2
3
4