➤ ./test.d --first arg --second arg2
["--first", "arg", "--second", "arg2"]
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.json : JSONValue, parseJSON; | |
| T fromJson(T)(JSONValue j) | |
| { | |
| import std.traits : isNumeric; | |
| // Handle JSON number and boolean values: | |
| static if (is(typeof(j.get!T))) | |
| return j.get!T; |
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 core.time : MonoTime; | |
| import std.stdio : stdin, writef; | |
| import std.string : wrap; | |
| const start = MonoTime.currTime; | |
| foreach (line; stdin.byLineCopy) | |
| { | |
| const now = MonoTime.currTime; | |
| const diff = now - start; |
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
| unittest | |
| { | |
| shared Atomic!int ai; | |
| assert(ai.get == 0); // atomicLoad / std::atomic<T>::load | |
| ai = 5; // atomicStore via opAssign / std::atomic<T>::operator= | |
| assert(ai.get == 5); // atomicLoad | |
| assert(ai.exchange(3) == 5); // atomicExchange / std::atomic<T>::exchange | |
| assert(ai.get == 3); // atomicLoad | |
| assert(ai.cas(3, 42)); // cas / std::atomic<T>::compare_exchange_strong | |
| assert(ai.get == 42); // atomicLoad |
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() | |
| { | |
| static immutable pairs = [__traits(allMembers, Pair)]; | |
| pragma (msg, pairs); // ["EURUSD", "GBPUSD", "USDCHF", "XAUUSD"] | |
| import std.stdio : writeln; | |
| "EURUSD".parseEnum!Pair.writeln; | |
| "GBPUSD".parseEnum!Pair.writeln; | |
| "USDCHF".parseEnum!Pair.writeln; |
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 : writeln; | |
| static struct Vec3 | |
| { | |
| float x, y, z; | |
| } | |
| auto soa = SoA!Vec3(5); |
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() | |
| { | |
| throw globalInstance!Error("This is an Error()", null); | |
| } | |
| T globalInstance(T, bool tls = true, Args...)(auto ref Args args) | |
| if (is(T == class)) | |
| { | |
| // There really should be a trait for this: | |
| enum classAlignment = 2 * (void*).sizeof; // until then, here's a reasonable guess :) |
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
| { pkgs ? import <nixpkgs> { } }: | |
| with pkgs; | |
| mkShell { | |
| buildInputs = [ | |
| fish | |
| git | |
| nodejs-12_x | |
| (yarn.override { nodejs = nodejs-12_x; }) | |
| gnumake | |
| python3 |
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.exception : enforce; | |
| import std.format : format; | |
| import std.file : exists, getcwd, isDir, isFile; | |
| import std.path : absolutePath, buildNormalizedPath, dirName, relativePath; | |
| import std.stdio : writeln, writefln; | |
| import std.range; | |
| void main(string[] args) | |
| { | |
| enforce(args.length == 2, "Usage:\n\tabs_to_rel_git_path <path>"); |