GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::move - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. algorithm
  3. move

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

function template
<algorithm>

std::move(C++11)

namespace std {
  template <class InputIterator, class OutputIterator>
  OutputIterator
    move(InputIterator first,
         InputIterator last,
         OutputIterator result);   // (1) C++11

  template <class InputIterator, class OutputIterator>
  constexpr OutputIterator
    move(InputIterator first,
         InputIterator last,
         OutputIterator result);   // (1) C++20

  template <class ExecutionPolicy, class ForwardIterator1,
            class ForwardIterator2>
  ForwardIterator2
    move(ExecutionPolicy&& exec,
         ForwardIterator1 first,
         ForwardIterator1 last,
         ForwardIterator2 result); // (2) C++17
}

概要

イテレータ範囲[first, last)の要素を出力イテレータ範囲にムーブする。

事前条件

result はイテレータ範囲[first,last)に含まれてはならない。

効果

イテレータ範囲[first,last) 内の要素を、それぞれ出力イテレータ範囲[result,result + (last - first)) へムーブする。

ムーブは first から順番に行い、0 以上 last - first 未満であるそれぞれの n について、*(result + n) = std::move(*(first + n)) を行う。

戻り値

result + (last - first)

計算量

正確に last - first 回ムーブ代入が行われる。

例

#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
#include <memory>

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;
  // v のそれぞれの要素を v2 へムーブする
  std::move(v.begin(), v.end(), std::back_inserter(v2));

  std::for_each(v2.begin(), v2.end(),
    [](const std::unique_ptr<int>& v) { std::cout << *v << std::endl; });
}

出力

0
1
2
3
4

実装例

template <class InputIterator, class OutputIterator>
OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
  while (first != last)
    *result++ = move(*first++);
  return result;
}

バージョン

言語

  • C++11

処理系

  • Clang: 3.0 ✅
  • GCC: 4.3.6 ✅
  • Visual C++: 2010 ✅, 2012 ✅, 2013 ✅, 2015 ✅

関連項目

  • C++11 右辺値参照・ムーブセマンティクス
  • ranges::move

参照

  • P0202R3 Add Constexpr Modifiers to Functions in <algorithm> and <utility> Headers
  • P0467R2 Iterator Concerns for Parallel Algorithms
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.