opApply and opApplyReverse
Q. Schroll via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 12 09:55:45 PST 2016
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);
More information about the Digitalmars-d
mailing list