2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 14:27:42 +00:00

Implement additive body states, rstl::binary_find

This commit is contained in:
Jack Andersen
2017-07-10 21:17:03 -10:00
parent 7e85ab932b
commit daef773f39
17 changed files with 371 additions and 71 deletions

View File

@@ -44,6 +44,21 @@ public:
T& operator[](size_t idx) { return x4_data[idx]; }
const T& operator[](size_t idx) const { return x4_data[idx]; }
};
template<class ForwardIt, class T>
ForwardIt binary_find(ForwardIt first, ForwardIt last, const T& value)
{
first = std::lower_bound(first, last, value);
return (!(first == last) && !(value < *first)) ? first : last;
}
template<class ForwardIt, class T, class GetKey>
ForwardIt binary_find(ForwardIt first, ForwardIt last, const T& value, GetKey getkey)
{
auto comp = [&](const auto& left, const T& right) { return getkey(left) < right; };
first = std::lower_bound(first, last, value, comp);
return (!(first == last) && !(value < getkey(*first))) ? first : last;
}
}
#endif // __RSTL_HPP__