1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-17 16:50:26 +02:00

IteratorRange utilities

This commit is contained in:
Paul Licameli 2017-10-03 23:55:06 -04:00
parent 5da84b74ae
commit fa53d521a2

View File

@ -909,12 +909,28 @@ struct IteratorRange : public std::pair<Iterator, Iterator> {
template <typename T> iterator find(const T &t) const
{ return std::find(this->begin(), this->end(), t); }
template <typename T> long index(const T &t) const
{
auto iter = this->find(t);
if (iter == this->end())
return -1;
return std::distance(this->begin(), iter);
}
template <typename T> bool contains(const T &t) const
{ return this->end() != this->find(t); }
template <typename F> iterator find_if(const F &f) const
{ return std::find_if(this->begin(), this->end(), f); }
template <typename F> long index_if(const F &f) const
{
auto iter = this->find_if(f);
if (iter == this->end())
return -1;
return std::distance(this->begin(), iter);
}
// to do: use std::all_of, any_of, none_of when available on all platforms
template <typename F> bool all_of(const F &f) const
{