Can you fix this code to avoid using pointers?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Mar 11 06:57:16 PST 2017
On Saturday, 11 March 2017 at 14:49:42 UTC, XavierAP wrote:
> But also I don't want to modify the function signature,
> certainly in this way.
It is already copied by the time you get in to the function
though because of the signature (unless they are constructed
in-place at the call site).
But you can also do an unrolled loop with AliasSeq
http://dpldocs.info/experimental-docs/std.meta.AliasSeq.html
import std.meta;
import std.exception;
void calc(double in1, double in2, double in3, double in4)
in {
foreach(ref item; AliasSeq!(in1, in2, in3, in4))
enforce(item > 0);
}
body { /* ... */ }
Note that if the loop body is large, this could bloat the code
slightly since a foreach over AliasSeq is always an unrolled
loop. But that's probably irrelevant to you.
More information about the Digitalmars-d-learn
mailing list