changeset 1556:ca435c6f02c8

DMD-1.014: associative array literals
author thomask
date Mon, 23 Jul 2007 18:46:06 +0000
parents 01c289574a6d
children de3b217ccd1e
files run/a/associative_array_23_A.d run/a/associative_array_23_B.d
diffstat 2 files changed, 70 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run/a/associative_array_23_A.d	Mon Jul 23 18:46:06 2007 +0000
@@ -0,0 +1,35 @@
+// $HeadURL$
+// $Date$
+// $Author$
+
+module dstress.run.a.associative_array_23_A;
+
+int main(){
+	char[][int] arr = [4:"vier", 0:"null", 2:"zwei"];
+
+	if(3 != arr.length){
+		assert(0);
+	}
+	
+	char[][] master_e = ["vier", "null", "zwei"];
+	int[] master_i = [4, 0, 2];
+
+	foreach(index, element; arr){
+		bool found = false;
+		foreach(pos, i; master_i){
+			if(index == i && element == master_e[pos]){
+				master_i = master_i[0 .. pos] ~ master_i[pos+1 .. $];
+				master_e = master_e[0 .. pos] ~ master_e[pos+1 .. $];
+				found = true;
+				break;
+			}
+		}
+		if(!found){
+			assert(0);
+		}
+	}
+	if(master_i.length){
+		assert(0);
+	}
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run/a/associative_array_23_B.d	Mon Jul 23 18:46:06 2007 +0000
@@ -0,0 +1,35 @@
+// $HeadURL$
+// $Date$
+// $Author$
+
+module dstress.run.a.associative_array_23_B;
+
+int main(){
+	auto arr = [4:"vier", 0:"null", 2:"zwei"];
+
+	if(3 != arr.length){
+		assert(0);
+	}
+	
+	char[][] master_e = ["vier", "null", "zwei"];
+	int[] master_i = [4, 0, 2];
+
+	foreach(index, element; arr){
+		bool found = false;
+		foreach(pos, i; master_i){
+			if(index == i && element == master_e[pos]){
+				master_i = master_i[0 .. pos] ~ master_i[pos+1 .. $];
+				master_e = master_e[0 .. pos] ~ master_e[pos+1 .. $];
+				found = true;
+				break;
+			}
+		}
+		if(!found){
+			assert(0);
+		}
+	}
+	if(master_i.length){
+		assert(0);
+	}
+	return 0;
+}