changeset 35:1d99d733cf13 tip @

day08: replace static foreach with workaround
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Tue, 16 Jan 2018 11:28:55 -0500
parents 049fb8e56025
children
files 2017/day08/app.d
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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);
   }