digitalmars.D - opApply and opApplyReverse
- Q. Schroll (25/25) Feb 12 2016 One upon time, we decided that we can replace opNeg, opCom, etc.
One upon time, we decided that we can replace opNeg, opCom, etc.
and opAdd, opSubtract, etc. by generic names opUnary and opBinary.
Why don't we have a single iteration operator? Can't we just
provide the "Reverse" information by some bool argument (or
string if you like maybe more functionality in the future) like
the other operators?
I'd suppose to make opApply and opApplyReverse aliases to
<newOp>!false / <newOp>!"Forward" and <newOp>!true /
<newOp>!"Reverse" for compatibility.
The workaround I use:
static pure opApp(bool rev)()
{
import std.format : format;
immutable code =
q{
int opApply%s(scope int delegate(ref Idcs) dg)
{
... (with %s everywhere something Reverse-generic happens)
}
}
return rev ? code.format("Reverse", ...)
: code.format("", ...);
}
mixin(opApp!false);
mixin(opApp!true);
Feb 12 2016








Q. Schroll <qs.il.paperinik gmail.com>