Safer casts

Janice Caron caron800 at googlemail.com
Sun May 11 15:24:34 PDT 2008


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?


>  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.



More information about the Digitalmars-d mailing list