summaryrefslogtreecommitdiff
path: root/src/common/algorithm.h
diff options
context:
space:
mode:
authorGravatar bunnei2019-10-15 16:41:52 -0400
committerGravatar GitHub2019-10-15 16:41:52 -0400
commitba0086e32dcbf11232fa2ae0864c28a991a56432 (patch)
tree1966d00f489790ec77e3d55e0b40d9e047272411 /src/common/algorithm.h
parentMerge pull request #2965 from FernandoS27/fair-core-timing (diff)
parentcommon/algorithm: Add description comment indicating intended algorithms (diff)
downloadyuzu-ba0086e32dcbf11232fa2ae0864c28a991a56432.tar.gz
yuzu-ba0086e32dcbf11232fa2ae0864c28a991a56432.tar.xz
yuzu-ba0086e32dcbf11232fa2ae0864c28a991a56432.zip
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 @@
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