diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-27 12:10:14 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-27 14:35:30 +0900 |
commit | a2ebdd4baa81d21a570792e6895ed8384e43c9c4 (patch) | |
tree | def489b7fa6e47a6af648efb22babb1824fa37f4 | |
parent | baee19241daffd50e0b32559cda64d5b6ede09a2 (diff) | |
download | libquotient-a2ebdd4baa81d21a570792e6895ed8384e43c9c4.tar.gz libquotient-a2ebdd4baa81d21a570792e6895ed8384e43c9c4.zip |
util.h: findFirstOf
A spin on the standard algorithm.
-rw-r--r-- | lib/util.h | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -191,6 +191,24 @@ namespace QMatrixClient iterator to; }; + /** A replica of std::find_first_of that returns a pair of iterators + * + * Convenient for cases when you need to know which particular "first of" + * [sFirst, sLast) has been found in [first, last). + */ + template<typename InputIt, typename ForwardIt, typename Pred> + inline std::pair<InputIt, ForwardIt> findFirstOf( + InputIt first, InputIt last, ForwardIt sFirst, ForwardIt sLast, + Pred pred) + { + for (; first != last; ++first) + for (auto it = sFirst; it != sLast; ++it) + if (pred(*first, *it)) + return std::make_pair(first, it); + + return std::make_pair(last, sLast); + } + /** A guard pointer that disconnects an interested object upon destruction * It's almost QPointer<> except that you have to initialise it with one * more additional parameter - a pointer to a QObject that will be |