GeezerVison is showing cpprefjp.github.io — std::rotate_copy - cpprefjp C++日本語リファレンス
最終更新日時:
2026年08月25日 12時11分17秒 (JST)
Akira Takahashi
が更新
履歴
編集
function template
<algorithm>
std:: rotate_copy
namespace std {
template < class ForwardIterator , class OutputIterator >
OutputIterator
rotate_copy ( ForwardIterator first ,
ForwardIterator middle ,
ForwardIterator last ,
OutputIterator result ); // (1) C++98
template < class ForwardIterator , class OutputIterator >
constexpr OutputIterator
rotate_copy ( ForwardIterator first ,
ForwardIterator middle ,
ForwardIterator last ,
OutputIterator result ); // (1) C++20
template < class ExecutionPolicy , class ForwardIterator1 , class ForwardIterator2 >
ForwardIterator2
rotate_copy ( ExecutionPolicy && exec ,
ForwardIterator1 first ,
ForwardIterator1 middle ,
ForwardIterator1 last ,
ForwardIterator2 result ); // (2) C++17
}
概要
middleの要素が先頭、middle-1の要素が末尾となるように、イテレータ範囲[first,last)の要素の並びを回転させ、その結果を出力の範囲へコピーする。
事前条件
[first,last) と [result,result + (last - first)) の範囲は重なっていてはならない
効果
0 以上 last - first 未満の整数 i について、*(result + i) = *(first + (i + (middle - first)) % (last - first)) という操作によって [first,last) の範囲を [result,result + (last - first)) の範囲へコピーする
戻り値
出力範囲の終端を指すイテレータresult + (last - first)
計算量
正確に last - first 回代入する。
例
出力
tatero
実装例
template < class ForwardIterator , class OutputIterator >
OutputIterator rotate_copy ( ForwardIterator first ,
ForwardIterator middle ,
ForwardIterator last ,
OutputIterator result ) {
return std::copy ( first , middle , std::copy ( middle , last , result ));
}
関連項目
参照