Can you fix this code to avoid using pointers?

XavierAP via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 11 04:45:10 PST 2017


On Saturday, 11 March 2017 at 12:35:42 UTC, XavierAP wrote:
> I do not really think it's a bad solution, to check several 
> scalar arguments that must obey the same condition; just 
> wondering if you have better ideas. Try to avoid modifying the 
> function's signature and defining custom types, unless you have 
> a really terrific idea.
>
> void calc(double in1, double in2, double in3, double in4)
> in {
>    foreach(const p; [&in1, &in2, &in3, &in4])
>       enforce(*p > 0);
> }
> body { /* ... */ }

Please imagine double is a type that I wanted to avoid copying, 
just check by ref. Same question :p


More information about the Digitalmars-d-learn mailing list