Skip to content

Instantly share code, notes, and snippets.

View run-dlang's full-sized avatar

Eleanor Cross run-dlang

View GitHub Profile
@run-dlang
run-dlang / main.d
Created April 7, 2018 13:18
Code shared from run.dlang.io.
import std.stdio;
import std.algorithm;
import std.meta;
import std.bitmanip;
import std.traits;
void main()
{
S s;
@run-dlang
run-dlang / main.d
Created April 12, 2018 10:42
Code shared from run.dlang.io.
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]
@run-dlang
run-dlang / main.d
Created April 13, 2018 14:51
Code shared from run.dlang.io.
///
@property ref auto opDispatch(string swizzle)() @safe pure nothrow
if (swizzle.length == 1)
{
alias componentNameToIndex = componentNameToIndexFactory!swizzle;
return data[componentNameToIndex!(swizzle[0])];
}
///
@run-dlang
run-dlang / main.d
Created April 13, 2018 14:52
Code shared from run.dlang.io.
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;
}
@run-dlang
run-dlang / main.d
Created April 14, 2018 19:36
Code shared from run.dlang.io. Run with '-vcolumns'
import std.stdio;
void main()
{
import std.string : outdent;
enum s = q{
void main() {
writeln("Hello, World!");
}
@run-dlang
run-dlang / main.d
Created April 15, 2018 09:30
Code shared from run.dlang.io.
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;
}
@run-dlang
run-dlang / main.d
Created April 15, 2018 09:30
Code shared from run.dlang.io.
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;
}
@run-dlang
run-dlang / main.d
Created April 15, 2018 19:46
Code shared from run.dlang.io.
import std.stdio;
void main()
{
writeln("Hello D");
}
@run-dlang
run-dlang / main.d
Created April 16, 2018 08:50
Code shared from run.dlang.io.
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)
{
@run-dlang
run-dlang / main.d
Created April 16, 2018 12:26
Code shared from run.dlang.io.
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)));