With statement extension
Artur Skawina via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 27 11:34:18 PDT 2016
On 04/27/16 15:55, deed via Digitalmars-d wrote:
>
> A stronger example would be a scope with two similar types, i.e.:
>
> void foo (Matrix matrix, SameType e1, SameType e2)
> {
> with (
> M : matrix.rawArr;
> Ex1 : e1.someProperties.someModulusX,
> Ey1 : e1.someProperties.someModulusY,
> Ex2 : e2.someProperties.someModulusX,
> Ey2 : e2.someProperties.someModulusY,
> v : e1.someProperties.aRatio)
>
> foreach (i; ...) foreach (j; ...) {
> M[...] = Ex1 > Ex2 ?
> 1/v^^2 * sqrt(v * (Ex1 + Ex2)^^2 + v^^2 * (Ey1 - Ey2)^^2) :
> 1/v^^2 * sqrt(v * (Ex1 + Ex2)^^2 + v^^2 * (Ey1 + Ey2)^^2) ;
> }
> }
>
> Current with-statement gets you next to nowhere here:
[...]
void foo (Matrix matrix, SameType e1, SameType e2)
{
ref M() { return matrix.rawArr; }
ref Ex1() { return e1.someProperties.someModulusX; }
ref Ey1() { return e1.someProperties.someModulusY; }
ref Ex2() { return e2.someProperties.someModulusX; }
ref Ey2() { return e2.someProperties.someModulusY; }
ref v() { return e1.someProperties.aRatio; }
foreach (i; ...) foreach (j; ...) {
M[...] = Ex1 > Ex2 ?
1/v^^2 * sqrt(v * (Ex1 + Ex2)^^2 + v^^2 * (Ey1 - Ey2)^^2) :
1/v^^2 * sqrt(v * (Ex1 + Ex2)^^2 + v^^2 * (Ey1 + Ey2)^^2) ;
}
}
artur
More information about the Digitalmars-d
mailing list