summaryrefslogtreecommitdiff
path: root/src/common/algorithm.h
diff options
context:
space:
mode:
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 @@
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#include <functional>
9
10// Algorithms that operate on iterators, much like the <algorithm> header.
11//
12// Note: If the algorithm is not general-purpose and/or doesn't operate on iterators,
13// it should probably not be placed within this header.
14
15namespace Common {
16
17template <class ForwardIt, class T, class Compare = std::less<>>
18ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) {
19 // Note: BOTH type T and the type after ForwardIt is dereferenced
20 // must be implicitly convertible to BOTH Type1 and Type2, used in Compare.
21 // This is stricter than lower_bound requirement (see above)
22
23 first = std::lower_bound(first, last, value, comp);
24 return first != last && !comp(value, *first) ? first : last;
25}
26
27} // namespace Common