名前空間
変種
操作

std::make_move_iterator

From cppreference.com
 
 
イテレータライブラリ
イテレータのコンセプト
イテレータのプリミティブ
アルゴリズムのコンセプトとユーティリティ
間接呼び出し可能コンセプト
共通アルゴリズム要件
(C++20)
(C++20)
(C++20)
ユーティリティ
(C++20)
イテレータアダプタ
Rangeアクセス
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
ヘッダ <iterator> で定義
template< class Iter >
std::move_iterator<Iter> make_move_iterator( Iter i );
(C++11以降)
(C++17 以降 constexpr)

make_move_iterator は、引数 i の型から推論された型で、与えられたイテレータ istd::move_iterator を構築する便利な関数テンプレートです。

目次

[編集] パラメータ

i - ムーブイテレータに変換される入力イテレータ

[編集] 戻り値

std::move_iterator<Iter>(std::move(i))

[編集]

#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);
}

実行結果の例

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

[編集] 不具合報告

以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。

DR 適用対象 公開された動作 正しい動作
LWG 2061 C++11 make_move_iterator は配列引数をポインタに変換しませんでした 変換するようにしました

[編集] 関連項目

間接参照すると右辺値になるイテレータアダプタ
(クラステンプレート) [編集]
(C++11)
引数をxvalueに変換する
(関数テンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)