Algorithms for DocumentModel

Change-Id: I9065951548a85190c991339f93cf57be2e1617da
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
Eike Ziller
2014-07-11 15:12:20 +02:00
parent b100d3bc9c
commit 292cf6c9e8
2 changed files with 24 additions and 21 deletions

View File

@@ -111,6 +111,18 @@ typename T::value_type findOr(const T &container, typename T::value_type other,
return *it;
}
template<typename T, typename F>
int indexOf(const T &container, F function)
{
typename T::const_iterator end = container.end();
typename T::const_iterator begin = container.begin();
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)
{