Skip to content

Instantly share code, notes, and snippets.

Avatar

Eleanor Cross run-dlang

View GitHub Profile
@run-dlang
run-dlang / main.d
Created Mar 25, 2022
Code shared from run.dlang.io.
View main.d
import std;
pragma(msg, "Compile time:");
void main()
{
writeln("Runtime:");
auto a = 3;
typeof("foo") b = "bar";
writeln(typeid(typeof(a)));
writeln(typeid(typeof(b)));
@run-dlang
run-dlang / main.d
Created Mar 25, 2022
Code shared from run.dlang.io.
View main.d
import std;
pragma(msg, "Compile time:");
void main()
{
writeln("Runtime:");
auto a = 3;
typeof("foo") b = "bar";
writeln(typeid(typeof(a)));
writeln(typeid(typeof(b)));
@run-dlang
run-dlang / main.d
Created Mar 19, 2022
Code shared from run.dlang.io.
View main.d
import std;
bool same(T)(T lhs, T rhs) { return true; }
bool different(U, V)(U lhs, V rhs)
if (!is(U == V))
{
return false;
}
alias isSameType = match!(different, same);
@run-dlang
run-dlang / main.d
Created Mar 18, 2022
Code shared from run.dlang.io.
View main.d
import std;
void main()
{
writeln("Hello D");
}
@run-dlang
run-dlang / main.d
Created Mar 16, 2022
Code shared from run.dlang.io.
View main.d
import std;
auto binarySearch(int[] nums, int target)
{
int left = -1;
int right = cast(int)nums.length - 1;
writeln(left, right);
if (target < nums[0]) {
return -1;
}
@run-dlang
run-dlang / main.d
Created Mar 15, 2022
Code shared from run.dlang.io. Run with '-unittest'
View main.d
void main()
{
import std.base64;
import std.stdio: write, writeln, writef, writefln;
import std.exception : assertThrown;
assertThrown!Base64Exception(Base64.decode("ab|c"));
}
@run-dlang
run-dlang / main.d
Created Mar 15, 2022
Code shared from run.dlang.io. Run with '-unittest'
View main.d
void main()
{
import std.base64;
import std.stdio: write, writeln, writef, writefln;
import std.exception : assertThrown;
assertThrown!Base64Exception(Base64.decode("ab|c"));
}
@run-dlang
run-dlang / main.d
Created Mar 15, 2022
Code shared from run.dlang.io. Run with '-unittest'
View main.d
void main()
{
import std.base64;
import std.stdio: write, writeln, writef, writefln;
import std.exception : assertThrown;
assertThrown!Base64Exception(Base64.decode("ab|c"));
}
@run-dlang
run-dlang / main.d
Created Mar 15, 2022
Code shared from run.dlang.io.
View main.d
import std.algorithm : each, map, cartesianProduct, filter;
import std.array : array;
import std.conv : to;
import std.format;
import std.range : chain, only;
import std.stdio;
import std.traits : EnumMembers;
enum Cpu
{
@run-dlang
run-dlang / main.d
Created Mar 12, 2022
Code shared from run.dlang.io.
View main.d
void main()
{
import std.exception, std.stdio, std.process;
auto result = ["whoami"].execute;
enforce(result.status == 0);
result.output.write;
}