Steven Schveighoffer wrote:
I gave this a lot of thought, and I think here is a possible solution:
the main reason I'm hesitant on this idea is because of code like this:
class X
{
auto opDotExp(string fname, T...)(T args)
{
if(fname == "blah")
return foo(args);
else if(fname == "blither")
return bar(args);
// else, nothing happens
}
}
Which leaves code open to lots of compiled code that doesn't do the
right thing (or throws some runtime exception). What would be nice is
if the default behavior is what statically bound functions do, that is,
compile error, and only let the cases be handled which the author
expects to handle.
class X
{
auto opDotExp(string fname, T...)(T args)
{
static if(fname == "blah")
return foo(args);
else static if(fname == "blither")
return bar(args);
else static assert(0, "Dunno how to "~fname);
}
}
Andrei