std::rotate_copy
提供: cppreference.com
ヘッダ <algorithm> で定義 | ||
(1) | ||
template<class ForwardIt, class OutputIt > OutputIt rotate_copy( ForwardIt first, ForwardIt n_first, | (C++20以前) | |
template<class ForwardIt, class OutputIt > constexpr OutputIt rotate_copy( ForwardIt first, ForwardIt n_first, | (C++20およびそれ以降) | |
template<class ExecutionPolicy, class ForwardIt1, class ForwardIt2 > ForwardIt2 rotate_copy( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 n_first, | (2) | (C++17およびそれ以降) |
1) 要素
n_first
が新しい範囲の最初の要素に、 n_first - 1
が最後の要素になるように、範囲 [first, last)
の要素を d_first
から始まる別の範囲にコピーします。2)(1) と同じですが、
policy
に従って実行されます。 このオーバーロードは、 std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> が true である場合にのみ、オーバーロード解決に参加します目次 |
[編集]引数
first, last | - | コピーする要素の範囲 |
n_first | - | 新しい範囲の先頭に現れるべき [first, last) 内の要素を指すイテレータ |
d_first | - | コピー先範囲の先頭 |
policy | - | 使用する実行ポリシー。 詳細は実行ポリシーを参照してください |
型の要件 | ||
-ForwardIt, ForwardIt1, ForwardIt2 は ForwardIterator の要件を満たさなければなりません。 | ||
-OutputIt は OutputIterator の要件を満たさなければなりません。 |
[編集]戻り値
最後にコピーされた要素の次の要素を指す出力イテレータ。
[編集]例外
テンプレート引数 ExecutionPolicy
を持つオーバーロードは以下のようにエラーを報告します。
- アルゴリズムの一部として呼び出された関数の実行が例外を投げ、
ExecutionPolicy
が3つの標準のポリシーのいずれかの場合は、 std::terminate が呼ばれます。 それ以外のあらゆるExecutionPolicy
については、動作は処理系定義です。 - アルゴリズムがメモリの確保に失敗した場合は、 std::bad_alloc が投げられます。
[編集]実装例
[編集]例
Run this code
#include <algorithm>#include <vector>#include <iostream> int main(){std::vector<int> src ={1, 2, 3, 4, 5};auto pivot =std::find(src.begin(), src.end(), 3);std::vector<int> dest(src.size()); std::rotate_copy(src.begin(), pivot, src.end(), dest.begin()); for(constauto&i : dest){std::cout<< i <<' ';}std::cout<<'\n';}
出力:
3 4 5 1 2
[編集]計算量
first
と last
の距離に比例。
[編集]関連項目
指定範囲の要素の順序を回転させます (関数テンプレート) |