Fully dynamic d by opDotExp overloading
Jason House
jason.james.house at gmail.com
Fri Apr 17 18:47:44 PDT 2009
Andrei Alexandrescu Wrote:
> Christopher Wright wrote:
> > Andrei Alexandrescu wrote:
> >> Yah, glad someone mentioned it :o). The best way is a blend - you can
> >> statically dispatch on some popular/heavily-used names, then rely on a
> >> hashtable lookup for dynamic stuff.
> >>
> >> Andrei
> >
> >
> > You suggest:
> >
> > auto opDotExp(string name)(...)
> > {
> > static if (name == "something")
> > {
> > code...
> > }
> > else
> > {
> > dynamic stuff
> > }
> > }
> >
> > That isn't very clear. Why not write it this way:
> >
> > auto opDotExp(string name, ...)
> > {
> > dynamic stuff
> > }
> >
> > auto something (...)
> > {
> > code...
> > }
>
> It's a good question. opDotExp leaves more flexibility because it allows
> for a host of compile-time manipulations, e.g. decide to forward to a
> member etc. Also consider this (probably Nick will turn blue):
>
> struct Pascalize(T)
> {
> T m;
> auto opDotExp(string name, T...)(T args)
> {
> return mixin("m."~tolower(name))(args);
> }
> }
>
> struct S { void foo() { ... } }
>
> Pascalize!S s;
> s.foo(); // works
> s.Foo(); // works too
> s.fOo(); // yup, works again
>
>
> Andrei
I find that funny. I can already imagine a developer that adds the equivalent of autocorrection while they type because they make trivial typos all teh timr
More information about the Digitalmars-d
mailing list