February 23, 2004
> Can we have a .name property for types?

I think that's a good idea, but you're motivating example is not the best.

Swapping efficient and (type-)safe compile time dispatching for runtime
string comparisons is the stuff of Java and .NET. ;)

> one possible use:
>
> ==================
> import std.stream;
>
> int main()
> {
>    char c;
>    TScan!(char).scan(c);
>    TPrint!(char).echo(c);
>    return 0;
> }
>
> template TScan(T) {
>    // Get information from stdin
>    void scan (out T t, ...) {
>      switch(T.name)
>      {
>        case "char"  : std.c.stdio.scanf("%c",&t);break;
>        case "char[]": std.c.stdio.scanf("%.*s", &t);break;
>        case "int"   : std.c.stdio.scanf("%d",&t);break;
>        case "double": std.c.stdio.scanf("%f",&t);break;
>      }
>    }
>
>    // Get information from stream
>    void read(out T t, ...) {
>      switch(T.name)
>      {
>        // ...
>      }
>    }
> }
>
> template TPrint(T) {
>    // Output information to stdout
>    void echo (T t, ...) {
>      switch(T.name)
>      {
>        case "char"  : printf("%c",t);break;
>        case "char[]": printf("%.*s",t);break;
>        case "int"   : printf("%d",t);break;
>        case "double": printf("%f",t);break;
>      }
>    }
>
>    // Output information to stream
>    void write (T t, ...) {
>      switch(T.name)
>      {
>        // ...
>      }
>    }
> }



February 25, 2004
Matthew wrote:
>>Can we have a .name property for types?
> 
> 
> I think that's a good idea, but you're motivating example is not the best.
> 
> Swapping efficient and (type-)safe compile time dispatching for runtime
> string comparisons is the stuff of Java and .NET. ;)
> 
> 
>>one possible use:
>>
[snip]
I'm affraid I'll have to go millitary on that one Matthew: "Private don't know."  Hopefully I won't have to hide behind this vail for much longer. In my defense I'd  like to say that I was simply trying to learn about templates at the time. The specific example I should have used was the switch. Of course, I requested this feature because I beleave it will facilitate the development of better i/o routines (i.e., scanf()/printf()).

Andrew

1 2
Next ›   Last »