2020-12-12 11:15:24 +00:00
|
|
|
public import std.array;
|
|
|
|
public import std.algorithm;
|
|
|
|
public import std.range;
|
|
|
|
public import std.string;
|
|
|
|
public import std.stdio;
|
|
|
|
public import std.traits;
|
|
|
|
public import std.variant;
|
|
|
|
|
2020-12-01 14:42:11 +00:00
|
|
|
import std.conv;
|
|
|
|
import std.exception;
|
|
|
|
import std.format;
|
|
|
|
|
|
|
|
class ArgumentException : Exception{
|
|
|
|
mixin basicExceptionCtors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for implementing
|
|
|
|
*
|
|
|
|
* Looks at the first argument string, and calls the delegate dgs[i + 1], while making sure nothing
|
|
|
|
goes out bounds.
|
|
|
|
*
|
|
|
|
* Params:
|
2020-12-05 11:16:58 +00:00
|
|
|
* part = The part to run.
|
2020-12-01 14:42:11 +00:00
|
|
|
* dgs = list of delegates. Which one will be called depends on args[0]
|
|
|
|
*/
|
2020-12-05 11:16:58 +00:00
|
|
|
R parts(R)(int part, R delegate()[] dgs ...) {
|
2020-12-01 14:42:11 +00:00
|
|
|
ulong len = dgs.length;
|
|
|
|
enforce!ArgumentException(part > 0 && part <= len, "This day supports parts %d to %d".format(1, len));
|
|
|
|
|
|
|
|
return dgs[part - 1]();
|
|
|
|
}
|