## digitalmars.D - Dinamic operator binding Proposal

• JDavidLS (23/23) Sep 21 2007 Class Obj
• Carlos Santander (11/43) Sep 22 2007 This has been suggested before, but there are ways to make it work now. ...
JDavidLS <jdavidls gmail.com> writes:
```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;
}
...
}
```
Sep 21 2007
Carlos Santander <csantander619 gmail.com> writes:
```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
```
Sep 22 2007