一:功能
对区域里面的元素进行分组,并不保证组内相等元素位置不变(稳定排序)
二:用法
#include <vector>
#include <algorithm>
#include <iostream>
struct Item {
int id;
bool is_selected;
};
struct Widget {
std::vector<Item> items;
};
Widget& get_widget() {
static Widget main_widget = {
.items = {
{0, false}, {1, true}, {2, false}, {3, true}, {4, false}, {5, true}
}
};
return main_widget;
}
int main() {
auto& widget = get_widget();
std::ranges::stable_partition(widget.items, &Item::is_selected);
for (auto &v : widget.items) {
std::cout << v.id << " ";
}
std::cout << "\n";
}