summaryrefslogtreecommitdiff
path: root/src/common/binary_find.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/binary_find.h')
-rw-r--r--src/common/binary_find.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/common/binary_find.h b/src/common/binary_find.h
new file mode 100644
index 000000000..5cc523bf9
--- /dev/null
+++ b/src/common/binary_find.h
@@ -0,0 +1,21 @@
1// Copyright 2019 yuzu emulator team
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <algorithm>
8
9namespace Common {
10
11template <class ForwardIt, class T, class Compare = std::less<>>
12ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) {
13 // Note: BOTH type T and the type after ForwardIt is dereferenced
14 // must be implicitly convertible to BOTH Type1 and Type2, used in Compare.
15 // This is stricter than lower_bound requirement (see above)
16
17 first = std::lower_bound(first, last, value, comp);
18 return first != last && !comp(value, *first) ? first : last;
19}
20
21} // namespace Common