From d8cd27196d1191ac344c7d14448783afbe0d17c7 Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Mon, 7 Apr 2025 06:32:25 +0000 Subject: [PATCH] feat(kernel/std): add std::sort implementations --- Kernel/include_std/algorithm | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Kernel/include_std/algorithm b/Kernel/include_std/algorithm index 33830c1a..f6028bc1 100644 --- a/Kernel/include_std/algorithm +++ b/Kernel/include_std/algorithm @@ -324,4 +324,42 @@ namespace std } return true; } + + template + constexpr void sort(RandomIt first, RandomIt last) + { + if (first == last) + return; + + for (RandomIt i = first; i != last; ++i) + { + for (RandomIt j = i + 1; j != last; ++j) + { + if (*j < *i) + std::swap(*i, *j); + } + } + } + + template + void sort(ExecutionPolicy &&policy, RandomIt first, RandomIt last); + + template + constexpr void sort(RandomIt first, RandomIt last, Compare comp) + { + if (first == last) + return; + + for (RandomIt i = first; i != last; ++i) + { + for (RandomIt j = i + 1; j != last; ++j) + { + if (comp(*j, *i)) + std::swap(*i, *j); + } + } + } + + template + void sort(ExecutionPolicy &&policy, RandomIt first, RandomIt last, Compare comp); }