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.
This commit is contained in:
baldurk
2024-03-19 20:14:27 +00:00
parent 7fdff69935
commit cc52e31657
2 changed files with 18 additions and 1 deletions
@@ -655,7 +655,7 @@ void AddRecentFile(rdcarray<rdcstr> &recentList, const rdcstr &file)
return;
}
if(recentList.contains(path))
if(recentList.contains(rdcstr(path)))
recentList.removeOne(path);
recentList.push_back(path);
+17
View File
@@ -638,8 +638,25 @@ public:
return -1;
}
template <class U>
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 <class U>
bool contains(const U &el) const
{
return indexOf(el) != -1;
}
// remove the first occurrence of an element
void removeOne(const T &el)
{