GeezerVison is showing cpprefjp.github.io — std::ranges::minmax_element - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function template
<algorithm>
std::ranges:: minmax_element (C++20)
namespace std :: ranges {
template < forward_iterator I ,
sentinel_for < I > S ,
class Proj = identity ,
indirect_strict_weak_order < projected < I , Proj >> Comp = ranges::less >
constexpr minmax_element_result < I >
minmax_element ( I first ,
S last ,
Comp comp = {},
Proj proj = {}); // (1) C++20
template < forward_range R ,
class Proj = identity ,
indirect_strict_weak_order < projected < iterator_t < R > , Proj >> Comp = ranges::less >
constexpr minmax_element_result < borrowed_iterator_t < R >>
minmax_element ( R && r ,
Comp comp = {},
Proj proj = {}); // (2) C++20
template < execution-policy Ep ,
random_access_iterator I ,
sized_sentinel_for < I > S ,
class Proj = identity ,
indirect_strict_weak_order < projected < I , Proj >> Comp = ranges::less >
minmax_element_result < I >
minmax_element ( Ep && exec ,
I first ,
S last ,
Comp comp = {},
Proj proj = {}); // (3) C++26
template < execution-policy Ep ,
sized-random-access-range R ,
class Proj = identity ,
indirect_strict_weak_order < projected < iterator_t < R > , Proj >> Comp = ranges::less >
minmax_element_result < borrowed_iterator_t < R >>
minmax_element ( Ep && exec ,
R && r ,
Comp comp = {},
Proj proj = {}); // (4) C++26
}
概要
[first, last) の範囲において、最小要素を指すイテレータと最大要素を指すイテレータの組を取得する。
(1): イテレータ範囲を指定する
(2): Rangeを直接指定する
(3): (1)の並列アルゴリズム版。実行ポリシーを指定する
(4): (2)の並列アルゴリズム版。実行ポリシーを指定する
戻り値
それぞれ、比較 invoke (comp, invoke (proj, *i), invoke (proj, *j)) によって判断し、同じ値の要素が複数ある場合は、最小の要素は最初の要素、最大の要素は最後の要素となる。
計算量
n を範囲の要素数とする場合、max (floor(3(n - 1) / 2), 0) 回の述語適用を行う。
例
基本的な使い方
出力
並列アルゴリズムの例 (C++26)
出力
min: 1
max: 9
バージョン
言語
処理系
参照