yohhoyの日記

技術的メモをしていきたい日記

2種類のstd::move関数

C++11標準ライブラリのstd::move関数テンプレートには、標準ヘッダ<utility>と<algorithm>とで用途の異なる2種類が存在する。

ヘッダ<utility>のmove
変数(lvalue値)に対してムーブセマンティクスを適用するためのヘルパ関数。
ヘッダ<algorithm>のmove
std::copyアルゴリズムのmove版。InputIterator範囲とOutputIteratorの3引数をとる。

2021-10-05追記:C++2b(C++23)に向けた提案P2446R0にてstd::views::moveレンジアダプタ追加が予定されている。

// Header <utility> synopsis
namespace std {
  // 20.2.3, forward/move:
  template <class T>
  typename remove_reference<T>::type&& move(T&&) noexcept;
}
// Header <algorithm> synopsis
namespace std {
  // 25.3.2, move:
  template<class InputIterator, class OutputIterator>
  OutputIterator move(InputIterator first, InputIterator last, OutputIterator result);
}

関連URL