binary_find.h 700 B

123456789101112131415161718192021
  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. namespace Common {
  7. template <class ForwardIt, class T, class Compare = std::less<>>
  8. ForwardIt BinaryFind(ForwardIt first, ForwardIt last, const T& value, Compare comp = {}) {
  9. // Note: BOTH type T and the type after ForwardIt is dereferenced
  10. // must be implicitly convertible to BOTH Type1 and Type2, used in Compare.
  11. // This is stricter than lower_bound requirement (see above)
  12. first = std::lower_bound(first, last, value, comp);
  13. return first != last && !comp(value, *first) ? first : last;
  14. }
  15. } // namespace Common