summaryrefslogtreecommitdiff
path: root/src/common/algorithm.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2019-10-15 16:41:52 -0400
committerGitHub <noreply@github.com>2019-10-15 16:41:52 -0400
commitba0086e32dcbf11232fa2ae0864c28a991a56432 (patch)
tree1966d00f489790ec77e3d55e0b40d9e047272411 /src/common/algorithm.h
parentcab2619aeb111bd6c5dbcc5adc0d2e8154a1e8fc (diff)
parentd5706346d7e95984a003bfeedf1b8ffed6dd9422 (diff)
Merge pull request #2977 from lioncash/algorithm
common: Rename binary_find.h to algorithm.h
Diffstat (limited to 'src/common/algorithm.h')
-rw-r--r--src/common/algorithm.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/common/algorithm.h b/src/common/algorithm.h
new file mode 100644
index 000000000..e21b1373c
--- /dev/null
+++ b/src/common/algorithm.h
@@ -0,0 +1,27 @@
+// Copyright 2019 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <algorithm>
+#include <functional>
+
+// Algorithms that operate on iterators, much like the <algorithm> header.
+//
+// Note: If the algorithm is not general-purpose and/or doesn't operate on iterators,
+// it should probably not be placed within this header.
+
+namespace Common {
+
+template <class ForwardIt, class T, class Compare = std::less<>>
+ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) {
+ // Note: BOTH type T and the type after ForwardIt is dereferenced
+ // must be implicitly convertible to BOTH Type1 and Type2, used in Compare.
+ // This is stricter than lower_bound requirement (see above)
+
+ first = std::lower_bound(first, last, value, comp);
+ return first != last && !comp(value, *first) ? first : last;
+}
+
+} // namespace Common