Richard Biener <rguent...@suse.de> writes:
>> Am 26.08.2022 um 18:40 schrieb Martin Jambor <mjam...@suse.cz>:
>> 
>> Hi,
>> 
>> This adds a method to binary search in a sorted array_slice.
>> 
>> The implementation is direct copy of vec:bsearch.  Moreover, to only
>> copy it once and not twice, I used const_cast in the non-const
>> variants to be able to use the const variants.  I hope that is
>> acceptable abuse of const_cast but I'll be happy to change that if
>> not.
>> 
>> Bootstrapped and tested along code that actually uses it on
>> x86_64-linux.  OK for trunk?
>
> Can you avoid the copying by using array slice bsearch from the vec<> bsearch?

IMO it would be better to transition to using <algorithm> routines
for this kind of thing (for new code).  In this case that would be
std::lower_bound.

Using std::lower_bound is more convenient because it avoids the void *
thing (you can use lambdas to capture any number of variables instead)
and because it works on subranges, not just whole ranges.

Thanks,
Richard

Reply via email to