algorithm.h 722 B

12345678910111213141516171819202122
  1. // Copyright 2019 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <algorithm>
  6. #include <functional>
  7. namespace Common {
  8. template <class ForwardIt, class T, class Compare = std::less<>>
  9. ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) {
  10. // Note: BOTH type T and the type after ForwardIt is dereferenced
  11. // must be implicitly convertible to BOTH Type1 and Type2, used in Compare.
  12. // This is stricter than lower_bound requirement (see above)
  13. first = std::lower_bound(first, last, value, comp);
  14. return first != last && !comp(value, *first) ? first : last;
  15. }
  16. } // namespace Common