Can you fix this code to avoid using pointers?

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 11 11:15:59 PST 2017


On Sat, Mar 11, 2017 at 12:45:10PM +0000, XavierAP via Digitalmars-d-learn wrote:
> 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

What about just:

	foreach (const ref p; [in1, in2, in3, in4])
		...

?


T

-- 
Stop staring at me like that! It's offens... no, you'll hurt your eyes!


More information about the Digitalmars-d-learn mailing list