summaryrefslogtreecommitdiff
path: root/core/templates
diff options
context:
space:
mode:
authormashumafi <mashumafi@gmail.com>2022-03-27 21:57:20 -0400
committermashumafi <mashumafi@gmail.com>2022-03-27 22:10:36 -0400
commit9c2bfeb2fbad050322a3899451179bb346af7f64 (patch)
tree10896593a644c5d3db81c577d697b5398665211e /core/templates
parenta0071029f2c4ec006d3443f25aa77e2c2c7a1ece (diff)
Const Ref Callable for custom sort/search
Diffstat (limited to 'core/templates')
-rw-r--r--core/templates/vector.h19
1 files changed, 12 insertions, 7 deletions
diff --git a/core/templates/vector.h b/core/templates/vector.h
index 0877e04e01..d87e76139b 100644
--- a/core/templates/vector.h
+++ b/core/templates/vector.h
@@ -97,24 +97,29 @@ public:
_FORCE_INLINE_ bool has(const T &p_val) const { return find(p_val) != -1; }
- template <class C>
- void sort_custom() {
+ void sort() {
+ sort_custom<_DefaultComparator<T>>();
+ }
+
+ template <class Comparator, bool Validate = SORT_ARRAY_VALIDATE_ENABLED, class... Args>
+ void sort_custom(Args &&...args) {
int len = _cowdata.size();
if (len == 0) {
return;
}
T *data = ptrw();
- SortArray<T, C> sorter;
+ SortArray<T, Comparator, Validate> sorter{ args... };
sorter.sort(data, len);
}
- void sort() {
- sort_custom<_DefaultComparator<T>>();
+ int bsearch(const T &p_value, bool p_before) {
+ return bsearch_custom<_DefaultComparator<T>>(p_value, p_before);
}
- int bsearch(const T &p_value, bool p_before) {
- SearchArray<T> search;
+ template <class Comparator, class Value, class... Args>
+ int bsearch_custom(const Value &p_value, bool p_before, Args &&...args) {
+ SearchArray<T, Comparator> search{ args... };
return search.bisect(ptrw(), size(), p_value, p_before);
}