Safer casts
Dee Girl
deegirl at noreply.com
Tue May 13 00:45:25 PDT 2008
Janice Caron Wrote:
> 2008/5/13 Dee Girl <deegirl at noreply.com>:
> > int array[] = [1, 2, 3];
> > int x = 5;
> > sort!((int a, int b) { return a + x < b + x; })(array);
> >
> > Two questions not one ^_^
> >
> > 1. Is the code inside sort!() as powerful as delegate?
>
> The code inside sort!() /is/ a delegate. It's an anonymous delegate,
> but its implementation is exactly the same as a delegate with a name.
> It's equivalent to
>
> int foo (int a, int b) { return a + x < b + x; };
> sort!(foo)(array);
Yes, excellent point. The codes are equivalent. But foo is not a delegate. It is a nested function. Like in Pascal. I am not sure how it can become delegate. Maybe Walter can answer because I see he writes here. Maybe when somebody takes address of foo. Dee Girl
More information about the Digitalmars-d
mailing list