Fix mis-use of std::lower_bound

Binary search in C++ is such a PITA. =/

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308106 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Kleckner 2017-07-15 18:10:15 +00:00
parent c09fbb030f
commit 0b189e17f8

View File

@ -88,9 +88,9 @@ private:
// Make sure the offset is somewhere in our items array.
if (Offset >= getLength())
return make_error<BinaryStreamError>(stream_error_code::stream_too_short);
auto Iter = std::lower_bound(
ItemEndOffsets.begin(), ItemEndOffsets.end(), Offset,
[](const uint32_t &A, const uint32_t &B) { return A <= B; });
++Offset;
auto Iter =
std::lower_bound(ItemEndOffsets.begin(), ItemEndOffsets.end(), Offset);
size_t Idx = std::distance(ItemEndOffsets.begin(), Iter);
assert(Idx < Items.size() && "binary search for offset failed");
return Idx;