Safer casts
Dee Girl
deegirl at noreply.com
Mon May 12 17:44:20 PDT 2008
Yigal Chripun Wrote:
> Dee Girl wrote:
> <snip>
> maybe I still didn't explain myself properly. I've used the term
> "sort-with-delegates" meaning a specific instance of sort when given a
> delegate as input. I thought this was clear enough, otherwise I would
> have simply said "sort".
> before you start sending me assembly code, let's go over it again and
> make sure we both understand each other:
> you take the sort template, stick in a delegate, mix for five minutes
> let is simmer for one more and viola: you got the exact same thing if
> you would have written sort as a regular function which receives a
> delegate parameter.
> the template takes the symbol it receives (the delegate name) and
> "embeds" it in the sort instance.
> both ways you get:
> 1) a call to sort
> 2) a call to the delegate
> the only difference is the number of parameters the sort function
> receives when called.
> the regular sort function can run different delegates at runtime (this
> is what you call "dynamic". the template has the call to the specific
> delegate embedded so for different delegates you need different sort
> instances.
Good. I think I understand. I want to be very sure, so I have a question from this code.
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?
2. Is the call inside sort direct or indirect? Thank you, Dee Girl
More information about the Digitalmars-d
mailing list