From 9c2bfeb2fbad050322a3899451179bb346af7f64 Mon Sep 17 00:00:00 2001 From: mashumafi Date: Sun, 27 Mar 2022 21:57:20 -0400 Subject: Const Ref Callable for custom sort/search --- core/templates/vector.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'core/templates') 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 - void sort_custom() { + void sort() { + sort_custom<_DefaultComparator>(); + } + + template + void sort_custom(Args &&...args) { int len = _cowdata.size(); if (len == 0) { return; } T *data = ptrw(); - SortArray sorter; + SortArray sorter{ args... }; sorter.sort(data, len); } - void sort() { - sort_custom<_DefaultComparator>(); + int bsearch(const T &p_value, bool p_before) { + return bsearch_custom<_DefaultComparator>(p_value, p_before); } - int bsearch(const T &p_value, bool p_before) { - SearchArray search; + template + int bsearch_custom(const Value &p_value, bool p_before, Args &&...args) { + SearchArray search{ args... }; return search.bisect(ptrw(), size(), p_value, p_before); } -- cgit v1.2.3