Safer casts

Yigal Chripun yigal100 at gmail.com
Sun May 11 15:37:23 PDT 2008


Janice Caron wrote:
> On 11/05/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>> your reply is correct but it is misleading.
> 
> Whose reply? What is this a reply to?
> 
> You might want to continue replying point-by-point. It makes things a
> lot easier to follow.
> 
> 
>>  you are correct in saying that there is only one mysort function
> 
> Who said that, and in what context?
> 
> 
sorry for that, that is a reply to dee.

>>  but
>>  every time you call it with a different comp delegate it needs to have a
>>  different sort instance.
> 
> OK, I see what you're saying. If I do
> 
>     sort!(English)(text);
>     sort!(Czech)(text);
> 
> then I do indeed get two instantiations (which presumably will sort
> text alphabetically by English and Czech rules respectively).
> 
> HOWEVER. If I write
> 
>     void mysort(T)(T[] array, int delegate(T,T) compare)
>     {
>         sort!(compare)(array);
>     }
> 
> then I have implemented your desired solution, trivially. And now I can call
> 
>     mysort(array,English);
>     mysort(array,Check);
> 
> and still there's only one instantiation of sort. It's exactly what
> Dee's been saying all along. You can make dynamic from static, but you
> can't make static from dynamic.

I don't follow. How can there be only one sort instance?
the mysort function uses both sorts so the code for both needs to be in
the executable...the first call instantiates the first sort for English,
and the second instantiates the second sort for Czech.




More information about the Digitalmars-d mailing list