Commit b712b1bc authored by Tobias Hunger's avatar Tobias Hunger

Utils: Make Utils::indexOf work with all iterator types

Change-Id: I5b9b577bdfb26bd03583ca8349b960625124a929
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent 33fc20ab
......@@ -161,18 +161,6 @@ typename T::element_type *findOr(const C<T, AllocC> &container, typename T::elem
return findOr(container, other, std::mem_fn(function));
}
template<typename T, typename F>
int indexOf(const T &container, F function)
{
typename T::const_iterator begin = std::begin(container);
typename T::const_iterator end = std::end(container);
typename T::const_iterator it = std::find_if(begin, end, function);
if (it == end)
return -1;
return it - begin;
}
template<typename T, typename F>
typename T::value_type findOrDefault(const T &container, F function)
{
......@@ -202,6 +190,22 @@ typename T::element_type *findOrDefault(const C<T, AllocC> &container, R (S::*fu
}
//////////////////
// index of:
//////////////////
template<typename C, typename F>
Q_REQUIRED_RESULT
int indexOf(const C& container, F function)
{
typename C::const_iterator begin = std::begin(container);
typename C::const_iterator end = std::end(container);
typename C::const_iterator it = std::find_if(begin, end, function);
return it == end ? -1 : std::distance(begin, it);
}
//////////////////
// max element
//////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment