Any trick for defining an operator overload in a different namespace?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Aug 31 18:19:28 PDT 2013
On 9/1/13, Ali Çehreli <acehreli at yahoo.com> wrote:
> This is the limitation of inner structs' not having an 'outer'
> reference, right?
Right, but this was just a workaround. Anyway I did just realize I can
use opDispatch for this:
-----
class C
{
this()
{
this.opts["foo"] = 1;
}
private auto opDispatch(string field : "opts")()
{
return this;
}
private void opIndexAssign(T)(T value, string option)
{
assign(option, value);
}
private void assign(string option, int value)
{
}
}
-----
It might seem a little funny that the only thing it does is just
returns 'this', which we already had. But I wanted to avoid writing
'this["foo"] = 1;'. Well at the end of the day this may or may not be
what I wanted, since I still want to hide opDispatch. Oh well.. :)
More information about the Digitalmars-d-learn
mailing list