mirror of
https://github.com/HenkKalkwater/aoc-2020
synced 2024-11-25 20:35:17 +00:00
25 lines
622 B
D
25 lines
622 B
D
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:
|
|
* part = The part to run.
|
|
* dgs = list of delegates. Which one will be called depends on args[0]
|
|
*/
|
|
R parts(R)(int part, R delegate()[] dgs ...) {
|
|
ulong len = dgs.length;
|
|
enforce!ArgumentException(part > 0 && part <= len, "This day supports parts %d to %d".format(1, len));
|
|
|
|
return dgs[part - 1]();
|
|
}
|