From cc52e316574f05341c1471fb203eff88518d4acb Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 19 Mar 2024 20:14:27 +0000 Subject: [PATCH] Add overload to search array with a different type without casting * Provided a compatible operator== overload exists, this can still be used to search the array. --- qrenderdoc/Code/Interface/PersistantConfig.cpp | 2 +- renderdoc/api/replay/rdcarray.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/qrenderdoc/Code/Interface/PersistantConfig.cpp b/qrenderdoc/Code/Interface/PersistantConfig.cpp index 2893fecdb..600a01e41 100644 --- a/qrenderdoc/Code/Interface/PersistantConfig.cpp +++ b/qrenderdoc/Code/Interface/PersistantConfig.cpp @@ -655,7 +655,7 @@ void AddRecentFile(rdcarray &recentList, const rdcstr &file) return; } - if(recentList.contains(path)) + if(recentList.contains(rdcstr(path))) recentList.removeOne(path); recentList.push_back(path); diff --git a/renderdoc/api/replay/rdcarray.h b/renderdoc/api/replay/rdcarray.h index 61e6828fe..cb4570a6f 100644 --- a/renderdoc/api/replay/rdcarray.h +++ b/renderdoc/api/replay/rdcarray.h @@ -638,8 +638,25 @@ public: return -1; } + template + int32_t indexOf(const U &el, size_t first = 0, size_t last = ~0U) const + { + for(size_t i = first; i < usedCount && i < last; i++) + { + if(elems[i] == el) + return (int32_t)i; + } + + return -1; + } + // return true if an element is found bool contains(const T &el) const { return indexOf(el) != -1; } + template + bool contains(const U &el) const + { + return indexOf(el) != -1; + } // remove the first occurrence of an element void removeOne(const T &el) {