Is opCast need, we have to!

Adam Ruppe destructionator at gmail.com
Fri Dec 3 05:50:38 PST 2010


foobar wrote:
> I still haven't seen one example of generic code that uses a generic conversion.
> I remain unconvinced about this point and would appreciate an example.

Like half the generic code I've written does that. A direct example
for this is my web.d - it makes automatic wrappers for D functions
that are callable through a cgi interface.

D:
int myFunction(float a, string b) { .... }

User's browser goes to:

myprogram/my-function?a=1.5&b=something

And sees the return value. The way the code works is:

(pseudocode)
foreach(member; thing.allMembers) {
   member.arguments args;
   foreach(i, arg; member.arguments) {
       args[i] = to!(typeof(arg))(cgi.get[arg.name]);
   }

   cgi.write(to!string(member(args)));
}


Everything in the web interface is string based on transport, so generic
conversions are done to and from all the D types used.


I did something similar with the command line version and with
my D2 dmdscript port.


More information about the Digitalmars-d mailing list