On 2009-11-20 02:18:03 -0800, Pelle Månsson <[email protected]> said:

Andrei Alexandrescu wrote:
Bill Baxter wrote:
On Thu, Nov 19, 2009 at 8:46 AM, Andrei Alexandrescu
<[email protected]> wrote:
grauzone wrote:
What's with opSomethingAssign (or "expr1[expr2] @= expr3" in general)?
opBinary doesn't seem to solve any of those.
opBinary does solve opIndex* morass because it only adds one function per
category, not one function per operator. For example:

struct T {
   // op can be "=", "+=", "-=" etc.
   E opAssign(string op)(E rhs) { ... }
   // op can be "=", "+=", "-=" etc.
   E opIndexAssign(string op)(size_t i, E rhs) { ... }
}

Rewrite
a.prop = x;   =>    a.opPropertyAssign!("prop", "=")(x);

to that and we're really getting somewhere!

--bb

I swear I was thinking of that.

Andrei
Is this doable without a performance drop?

These are compile-time string mixin magic. It might make your code compile slower, but the metaprogramming engine in D is already 1000000000x faster than C++.

Reply via email to