enforce()?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jul 19 08:10:03 PDT 2010


On 07/19/2010 09:27 AM, Steven Schveighoffer wrote:
> On Mon, 19 Jul 2010 09:36:54 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>
>> On 07/19/2010 06:36 AM, Steven Schveighoffer wrote:
>>> Just thinking out loud here, couldn't you use the predicate already in
>>> AssumeSorted? I mean, if you're going to pass AssumeSorted into find,
>>> you don't want to also specify the predicate as then the range just
>>> becomes a standard range.
>>>
>>> There must be some kind of way to use template constraints to kill the
>>> predicate arg to find when the range is an AssumeSorted struct. If not,
>>> there should be.
>>
>> That's a good idea. The find predicate that could be derived from
>> AssumeSorted's predicate pred would be !pred(a, b) && !pred(b, a).
>>
>> Thanks, Steve.
>
> You're welcome :)
>
> BTW, you don't need the combo predicate until the very end. Basically,
> you do a binary search for the first element where pred(a, E) is false
> (where E is the target), and then see if pred(E, a) is also false on
> that element (to test for equality).

You mean like this? :o)

http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/algorithm.d?rev=1279#L4703


Andrei



More information about the Digitalmars-d mailing list