Implicit castable structs

Dan murpsoft at hotmail.com
Wed Jan 9 17:15:44 PST 2008


0ffh Wrote:

> Frank Benoit wrote:
> > opCast is also not really good.
> > passing a null pointer would crash then. (or not?)
> 
> Yes, IIRC there was some obnoxious "assert(this !is null);"
> in all non-static member functions...
> 
> regards, frank

I *need* to be able to go:

Value myValue = 4;
int bob = myValue;

At the moment I'm accomplishing that by doing:

Value myValue = 4;
int bob = Value.toInteger();

Which is essentially identical to opCast(), except it gets ugly.  It's pretty clear to me that Value is performing implicit opAssign/opCall when something goes in, and likewise it would be clear with opCast.

The other major place I'd like it to handle this is with functions.

I can't do this:

Value myFunc() {
   return 4;
}

or this:

Value myFunc(Value self, Value cc) { bla bla bla }
myFunc(3,5);

If I got all this opCall/opAssign/opCast sorted out, my source would be about 15% smaller because a fair chunk of it is type conversions to handle ECMAScript's var.

Regards,
Dan



More information about the Digitalmars-d mailing list