digitalmars.D - Overload on opDispatch ?
- Jacob Carlborg (21/21) Dec 05 2009 Would it be a good idea to allow overloading on opDispatch to make the
- Tim Matthews (6/31) Dec 05 2009 Do you think it would be a good idea? or just want to know what others
Would it be a good idea to allow overloading on opDispatch to make the
following compile, what do you think?
import std.stdio;
class C
{
void opDispatch(string s, ARGS...) (ARGS args)
{
writefln("S.opDispatch('%s', %s)", s, typeof(args).stringof);
}
void foo (string s)
{
writeln("in asd");
}
}
void main()
{
C c = new C;
c.foo("bar"); // calls C.foo
c.foo("bar", "bar"); // calls C.opDispatch
c.foo(3); // calls C.opDispatch
}
Dec 05 2009
Jacob Carlborg wrote:
Would it be a good idea to allow overloading on opDispatch to make the
following compile, what do you think?
import std.stdio;
class C
{
void opDispatch(string s, ARGS...) (ARGS args)
{
writefln("S.opDispatch('%s', %s)", s, typeof(args).stringof);
}
void foo (string s)
{
writeln("in asd");
}
}
void main()
{
C c = new C;
c.foo("bar"); // calls C.foo
c.foo("bar", "bar"); // calls C.opDispatch
c.foo(3); // calls C.opDispatch
}
Do you think it would be a good idea? or just want to know what others
think for no obvious motive? If the latter: absolutely not. It would be
a major source of bugs. That code would be much safer if C.foo was a
private method that opdispatch called when it determines its arguments
met the requirements.
Dec 05 2009








Tim Matthews <tim.matthews7 gmail.com>