This file contains hidden or 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
| import std.stdio; | |
| import std.algorithm; | |
| import std.meta; | |
| import std.bitmanip; | |
| import std.traits; | |
| void main() | |
| { | |
| S s; |
This file contains hidden or 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
| void main() | |
| { | |
| import std.stdio: write, writeln, writef, writefln; | |
| int[3] s; | |
| int[3] t; | |
| s = t; // the 3 elements of t are copied into s | |
| s[] = t; // the 3 elements of t are copied into s | |
| s[] = t[]; // the 3 elements of t are copied into s | |
| s[1..2] = t[0..1]; // same as s[1] = t[0] |
This file contains hidden or 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
| /// | |
| @property ref auto opDispatch(string swizzle)() @safe pure nothrow | |
| if (swizzle.length == 1) | |
| { | |
| alias componentNameToIndex = componentNameToIndexFactory!swizzle; | |
| return data[componentNameToIndex!(swizzle[0])]; | |
| } | |
| /// |
This file contains hidden or 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
| private static ptrdiff_t[swizzle.length] computeSwizzleIndecies(string swizzle)() | |
| { | |
| ptrdiff_t[swizzle.length] result; | |
| alias componentNameToIndex = componentNameToIndexFactory!swizzle; | |
| static foreach (componentIndex, coordinateName; swizzle) | |
| { | |
| result[componentIndex] = componentNameToIndex!coordinateName; | |
| } |
This file contains hidden or 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
| import std.stdio; | |
| void main() | |
| { | |
| import std.string : outdent; | |
| enum s = q{ | |
| void main() { | |
| writeln("Hello, World!"); | |
| } |
This file contains hidden or 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
| T[m][n] matrixify(T, size_t n, size_t m)(T[n] a1, T[m] a2) | |
| { | |
| typeof(return) result; | |
| foreach (ix1, e; a1) | |
| foreach (ix2, e2; a2) | |
| result[ix1][ix2] = e + e2; | |
| return result; | |
| } |
This file contains hidden or 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
| T[m][n] matrixify(T, size_t n, size_t m)(T[n] a1, T[m] a2) | |
| { | |
| typeof(return) result; | |
| foreach (ix1, e; a1) | |
| foreach (ix2, e2; a2) | |
| result[ix1][ix2] = e + e2; | |
| return result; | |
| } |
This file contains hidden or 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
| import std.stdio; | |
| void main() | |
| { | |
| writeln("Hello D"); | |
| } |
This file contains hidden or 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
| void main() | |
| { | |
| import std.stdio: write, writeln, writef, writefln; | |
| struct Point | |
| { | |
| private double[] p; | |
| // Forward all undefined symbols to p | |
| this; | |
| double dot(Point rhs) | |
| { |
This file contains hidden or 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
| import std.stdio; | |
| void main() | |
| { | |
| import std.range.primitives : isInputRange; | |
| import std.traits : ReturnType; | |
| assert(is(typeof(NoRange.init) == NoRange)); | |
| assert(is(ReturnType!((NoRange r) => r.empty) == bool)); | |
| assert(is(typeof((return ref NoRange r) => r.front))); |