BasicMathOp

@property
string
BasicMathOp
(
string fields_str
)
(
)
if (
isArrayAccessString(fields_str, SEP, true)
)

Examples

1 static struct Val
2 {
3     float v1 = 0;
4     double v2 = 0;
5     mixin( BasicMathOp!"v1 v2" );
6 }
7 
8 static assert( isAssignable!(Unqual!Val,Unqual!Val) );
9 static assert( is( typeof(Val.init + Val.init) == Val ) );
10 static assert( is( typeof(Val.init - Val.init) == Val ) );
11 static assert( is( typeof( cast(Val)(Val.init * 0.5) ) ) );
12 static assert( is( typeof( cast(Val)(Val.init / 0.5) ) ) );
13 
14 static assert( hasBasicMathOp!Val );
15 
16 auto p1 = Val( 1, 2 );
17 auto p2 = Val( 2, 3 );
18 
19 assert( p1 + p2 == Val(3,5) );
20 assert( p2 - p1 == Val(1,1) );
21 assert( p1 * 3 == Val(3,6) );
22 assert( p1 / 2 == Val(0.5,1) );
23 
24 static struct Comp
25 {
26     string str;
27     float val; 
28     float time = 0;
29     mixin( BasicMathOp!"val" );
30 }
31 
32 static assert( hasBasicMathOp!Comp );
33 
34 auto c1 = Comp( "ololo", 10, 1.3 );
35 auto c2 = Comp( "valav", 5, .8 );
36 
37 assert( c1 + c2 == Comp("ololo", 15, 1.3) );
1 static struct Val
2 {
3     float v1 = 0;
4     double v2 = 0;
5     mixin( BasicMathOp!"v1 v2" );
6 }
7 
8 auto p1 = Val( 1, 2 );
9 auto p2 = Val( 2, 3 );
10 
11 auto p3 = p1 + p2;
12 p1 += p2;
13 assert( p1 == p3 );
1 static struct Vec
2 {
3     double x = 0, y = 0;
4     mixin( BasicMathOp!"x y" );
5 }
6 
7 static assert( hasBasicMathOp!Vec );
8 
9 static struct Point
10 {
11     Vec pos, vel;
12     this( in Vec p, in Vec v )
13     {
14         pos = p;
15         vel = v;
16     }
17     mixin( BasicMathOp!"pos vel" );
18 }
19 
20 static assert( hasBasicMathOp!Vec );
1 static struct Vec { double x=0, y=0; }
2 static assert( !hasBasicMathOp!Vec );
3 static struct Point 
4 { 
5     Vec pos, vel; 
6     string str;
7     float val;
8     mixin( BasicMathOp!"pos.x pos.y vel.x vel.y val" ); 
9 }
10 static assert( hasBasicMathOp!Point );
11 auto a = Point( Vec(1,2), Vec(2,3), "hello", 3 );
12 assert( a + a == Point( Vec(2,4), Vec(4,6), "hello", 6 ) );
13 assert( a * 2 == Point( Vec(2,4), Vec(4,6), "hello", 6 ) );

Meta