# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1516120135 18000 # Node ID 1d99d733cf13b69f23a24d1143bf5d534a477be2 # Parent 049fb8e56025eaa139dd4690553e2973cf498b25 day08: replace static foreach with workaround diff --git a/2017/day08/app.d b/2017/day08/app.d --- a/2017/day08/app.d +++ b/2017/day08/app.d @@ -5,10 +5,17 @@ int[string] registers; int maxSoFar = 0; +bool function(int,int)[string] comparisons; -bool function(int,int)[string] comparisons; -static foreach(cmp; ["<", ">", "==", "<=", ">=", "!="]) { - comparisons[cmp] = mixin("function(int a, int b) => a "~cmp~" b"); +auto getComparisons(Args...)() { + foreach(cmp; Args) { + comparisons[cmp] = mixin("function(int a, int b) => a "~cmp~" b"); + } + return comparisons; +} + +shared static this() { + comparisons = getComparisons!("<", ">", "==", "<=", ">=", "!="); } void evalInstruction(string line) { @@ -31,7 +38,6 @@ } void main(string[] args) { - foreach(line; File(args[1]).byLineCopy) { evalInstruction(line); }