Safer casts

Bruno Medeiros brunodomedeiros+spam at com.gmail
Tue Jun 10 10:33:12 PDT 2008


Sean Kelly wrote:
> 
> So you're saying I could do this:
> 
> void myfunc( bool delegate(int,int) dg )
> {
>     int[] buf = [1,2,3,4,5].dup;
>     sort!(dg)( buf );
> }
> 
> I thought alias parameters had to be resolvable at compile-time.  Interesting.
> 

Hum, I thought the same. And frankly I couldn't see how it could work 
otherwise, so it took me a while, and several experimentations, to 
figure out how it works.
Apparently, if the alias parameter is local, it is as if the template 
body is instantiated in the local scope where the template instance 
occurs, and if the template contains a function, it is as if the 
function used an outer local variable (and thus the function becomes a 
nested function).

After this, didn't took me long to cook up a bug using this feature :P :
http://d.puremagic.com/issues/show_bug.cgi?id=2148

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list