mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
cleanup: implement index_of() and index_of_if() generics
Search the index of an item in a container. Compare by equality or a lambda. The lack of these have annoyed me for a long time. Return the index of the first found element or -1 if no element found. Currently, only supports random-access operators. Might be trivially changed for forward iterators. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
df5bf728f9
commit
691d9e86de
3 changed files with 23 additions and 19 deletions
|
@ -242,10 +242,8 @@ int DivePictureModel::rowCount(const QModelIndex&) const
|
|||
|
||||
int DivePictureModel::findPictureId(const std::string &filename)
|
||||
{
|
||||
for (int i = 0; i < (int)pictures.size(); ++i)
|
||||
if (pictures[i].filename == filename)
|
||||
return i;
|
||||
return -1;
|
||||
return index_of_if(pictures, [&filename](const PictureEntry &p)
|
||||
{ return p.filename == filename; });
|
||||
}
|
||||
|
||||
static void addDurationToThumbnail(QImage &img, duration_t duration)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue