Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1018cab
commit e6d32b9
Showing
1 changed file
with
61 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,69 @@ | ||
import std.stdio; | ||
import std.complex; | ||
alias MT = MyStruct!int; | ||
|
||
void main() | ||
struct MyStruct(T) | ||
{ | ||
alias T = Complex!float; | ||
T x; | ||
|
||
T iV = complex(1.0f, 1.0f); | ||
T[] arr = [iV, 2 * iV, 3 * iV, 4 * iV, 5 * iV, 6 * iV]; | ||
Complex!float[] result = new T[arr.length]; | ||
this(T y) | ||
{ | ||
x = y; | ||
} | ||
|
||
MyStruct!T opBinary(string op)(MyStruct!T y) const | ||
{ | ||
alias C = typeof(return); | ||
auto w = C(this.x); | ||
return w.opOpAssign!(op)(y); | ||
} | ||
|
||
MyStruct!T opBinaryRight(string op)(MyStruct!T y) const | ||
{ | ||
return opBinary!(op)(y); | ||
} | ||
|
||
ref MyStruct opOpAssign(string op, T)(const MyStruct!T z) | ||
{ | ||
mixin ("x "~op~"= z.x;"); | ||
return this; | ||
} | ||
|
||
MyStruct!T opBinary(string op)(T y) const | ||
{ | ||
alias C = typeof(return); | ||
auto w = C(this.x); | ||
return w.opOpAssign!(op)(y); | ||
} | ||
|
||
MyStruct!T opBinaryRight(string op)(T y) const | ||
{ | ||
return opBinary!(op)(y); | ||
} | ||
|
||
ref MyStruct opOpAssign(string op, T)(const T z) | ||
{ | ||
mixin ("x "~op~"= z;"); | ||
return this; | ||
} | ||
} | ||
|
||
void test() | ||
{ | ||
MT s = MyStruct!int(1); | ||
MT[] arr = [s, 2 * s, 3 * s, 4 * s, 5 * s, 6 * s]; | ||
MT[] result = new MT[arr.length]; | ||
|
||
result[] = arr[] + iV; | ||
result[] = iV + arr[]; | ||
result[] = arr[] + s; | ||
result[] = s + arr[]; | ||
|
||
result[] = arr[] - iV; | ||
result[] = iV - arr[]; | ||
result[] = arr[] - s; | ||
result[] = s - arr[]; | ||
|
||
result[] = arr[] * iV; | ||
result[] = iV * arr[]; | ||
result[] = arr[] * s; | ||
result[] = s * arr[]; | ||
|
||
result[] = arr[] / iV; | ||
result[] = iV / arr[]; | ||
result[] = arr[] / s; | ||
result[] = s / arr[]; | ||
|
||
result[] = arr[] ^^ iV; | ||
result[] = iV ^^ arr[]; | ||
} | ||
result[] = arr[] ^^ s; | ||
result[] = s ^^ arr[]; | ||
} |