aboutsummaryrefslogtreecommitdiff
path: root/lib/util.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-27 18:34:28 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-07-27 18:34:28 +0900
commit84aa055bba602635599def37915b96ccf3f63484 (patch)
tree59857c792f913871ab70385fb7e9f037fa58973a /lib/util.h
parent284b751ee424985341812a32721227112160a905 (diff)
parentc7e4d01c479452aad4616ee2d5a285f4fe0565aa (diff)
downloadlibquotient-84aa055bba602635599def37915b96ccf3f63484.tar.gz
libquotient-84aa055bba602635599def37915b96ccf3f63484.zip
Merge branch 'kitsune-local-echo'
Diffstat (limited to 'lib/util.h')
-rw-r--r--lib/util.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/util.h b/lib/util.h
index c491ff89..7769abce 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -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