GeezerVison is showing cpprefjp.github.io — std::ranges::partial_sort_copy - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function template
<algorithm>
std::ranges:: partial_sort_copy (C++20)
namespace std :: ranges {
template < input_iterator I1 ,
sentinel_for < I1 > S1 ,
random_access_iterator I2 , sentinel_for < I2 > S2 ,
class Comp = ranges::less ,
class Proj1 = identity ,
class Proj2 = identity >
requires indirectly_copyable < I1 , I2 > &&
sortable < I2 , Comp , Proj2 > &&
indirect_strict_weak_order < Comp , projected < I1 , Proj1 > , projected < I2 , Proj2 >>
constexpr partial_sort_copy_result < I1 , I2 >
partial_sort_copy ( I1 first ,
S1 last ,
I2 result_first ,
S2 result_last ,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}); // (1) C++20
template < input_range R1 ,
random_access_range R2 ,
class Comp = ranges::less ,
class Proj1 = identity ,
class Proj2 = identity >
requires indirectly_copyable < iterator_t < R1 > , iterator_t < R2 >> &&
sortable < iterator_t < R2 > , Comp , Proj2 > &&
indirect_strict_weak_order <
Comp ,
projected < iterator_t < R1 > , Proj1 > ,
projected < iterator_t < R2 > , Proj2 >
>
constexpr partial_sort_copy_result < borrowed_iterator_t < R1 > , borrowed_iterator_t < R2 >>
partial_sort_copy ( R1 && r ,
R2 && result_r ,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}); // (2) C++20
template < execution-policy Ep ,
random_access_iterator I1 ,
sized_sentinel_for < I1 > S1 ,
random_access_iterator I2 ,
sized_sentinel_for < I2 > S2 ,
class Comp = ranges::less ,
class Proj1 = identity ,
class Proj2 = identity >
requires indirectly_copyable < I1 , I2 > &&
sortable < I2 , Comp , Proj2 > &&
indirect_strict_weak_order < Comp , projected < I1 , Proj1 > , projected < I2 , Proj2 >>
partial_sort_copy_result < I1 , I2 >
partial_sort_copy ( Ep && exec ,
I1 first ,
S1 last ,
I2 result_first ,
S2 result_last ,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}); // (3) C++26
template < execution-policy Ep ,
sized-random-access-range R1 ,
sized-random-access-range R2 ,
class Comp = ranges::less ,
class Proj1 = identity ,
class Proj2 = identity >
requires indirectly_copyable < iterator_t < R1 > , iterator_t < R2 >> &&
sortable < iterator_t < R2 > , Comp , Proj2 > &&
indirect_strict_weak_order <
Comp ,
projected < iterator_t < R1 > , Proj1 > ,
projected < iterator_t < R2 > , Proj2 >
>
partial_sort_copy_result < borrowed_iterator_t < R1 > , borrowed_iterator_t < R2 >>
partial_sort_copy ( Ep && exec ,
R1 && r ,
R2 && result_r ,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}); // (4) C++26
}
概要
範囲を部分的にソートした結果を他の範囲にコピーする
(1): イテレータ範囲を指定する
(2): Rangeを直接指定する
(3): (1)の並列アルゴリズム版。実行ポリシーを指定する
(4): (2)の並列アルゴリズム版。実行ポリシーを指定する
効果
N = min (last - first, result_last - result_first) とする。
[first,last) にある要素の中から、N 個の要素をソート済みの状態で [result_first,result_first + N) に配置する。
戻り値
計算量
ほぼ (last - first) * log(N) 回の比較を行う
例
基本的な使い方
出力
12
並列アルゴリズムの例 (C++26)
出力
1 1 2
バージョン
言語
処理系
参照