template <class Compare = less<T>>
void sort(Compare comp = Compare()); // (1) C++26
概要
要素を並べ替える。
事前条件
型Tがhiveに対してMoveInsertableであり、かつMoveAssignableかつSwappableであること。
効果
関数オブジェクトcompに基いて*thisの要素を並べ替える。例外が送出された場合、*thisの要素の順序は未規定である。
戻り値
なし
計算量
Nをsize()として、$O(N \log N)$回の比較
備考
- メモリを確保する可能性がある。
*thisの要素を指す参照・ポインタ・イテレータ、および終端イテレータは無効化される可能性がある。- この操作は安定であることを要求されない。
例
#include <hive>
#include <print>
int main()
{
std::hive<int> h = {3, 1, 4, 1, 5, 2};
// 昇順に並べ替える
h.sort();
for (int x : h) {
std::print("{} ", x);
}
std::println("");
}
出力
1 1 2 3 4 5
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌
関連項目
参照
- P0447R28 Introduction of
std::hiveto the standard library- C++26で
hiveが追加された
- C++26で