Iterator invalidation in lower/upper_bound_index

Error ocured in regression_tests/filter_mesh/test.py
This commit is contained in:
Olaf Schumann 2022-01-06 14:29:23 +01:00
parent 0cf7d92837
commit b150a58a11

View file

@ -16,16 +16,14 @@ typename std::iterator_traits<It>::difference_type lower_bound_index(
{
if (*first == value)
return 0;
It index = std::lower_bound(first, last, value) - 1;
return (index == last) ? -1 : index - first;
return std::lower_bound(first, last, value) - first - 1;
}
template<class It, class T>
typename std::iterator_traits<It>::difference_type upper_bound_index(
It first, It last, const T& value)
{
It index = std::upper_bound(first, last, value) - 1;
return (index == last) ? -1 : index - first;
return std::upper_bound(first, last, value) - first - 1;
}
} // namespace openmc