Dinamic operator binding Proposal
Carlos Santander
csantander619 at gmail.com
Sat Sep 22 07:57:11 PDT 2007
JDavidLS escribió:
> Class Obj
> {
> uint a,b;
>
> Str possibleOpCall1(uint x, uint y){a += y; b -=x;}
>
> Str possibleOpCall2(uint x, uint y){a -= x; b += y;}
>
> Str delegate(uint, uint) opCall = &possibleOpCall1;
>
> void changeMode()
> {
> opCall = &opssibleOpCall2;
> }
> }
>
> ¿¿dinamic operator bindigis facible on structs??
>
> struct Blk
> {
> uint a,b;
> Str function(uint, uint) opCall = &possibleOpCall1;
> static Str possibleOpCall1(ref Blk blk, uint x, uint y)
> {
> blk.a += y;
> blk.b -=x;
> }
> ...
> }
>
>
>
This has been suggested before, but there are ways to make it work now. Perhaps
the most natural is just to add one level of indirection. In your example:
Str delegate(uint, uint) myOpCall = &possibleOpCall1;
void changeMode()
{
myOpCall = &opssibleOpCall2;
}
Str opCall(uint x, uint y){ return myOpCall(x,y); }
--
Carlos Santander Bernal
More information about the Digitalmars-d
mailing list