Test non-default compare template argument in std::map
diff --git a/Examples/test-suite/csharp/li_std_map_runme.cs b/Examples/test-suite/csharp/li_std_map_runme.cs
index b21c81e..51510c9 100644
--- a/Examples/test-suite/csharp/li_std_map_runme.cs
+++ b/Examples/test-suite/csharp/li_std_map_runme.cs
@@ -240,6 +240,20 @@
throw new Exception("Key test (2) on complex key map failed");
}
+ // Custom compare function
+ {
+ StringLengthNumberMap slmap = new StringLengthNumberMap();
+ li_std_map.populate(slmap);
+
+ string keys = string.Join(" ", new List<string>(slmap.Keys));
+ if (keys != "a aa zzz xxxx aaaaa")
+ throw new Exception("Keys are wrong or in wrong order: " + keys);
+
+ string values = string.Join(" ", new List<int>(slmap.Values));
+ if (values != "1 2 3 4 5")
+ throw new Exception("Values are wrong or in wrong order: " + values);
+ }
+
// All done
}
}
diff --git a/Examples/test-suite/li_std_map.i b/Examples/test-suite/li_std_map.i
index bf24c35..238cc33 100644
--- a/Examples/test-suite/li_std_map.i
+++ b/Examples/test-suite/li_std_map.i
@@ -117,4 +117,25 @@
}
}
+%ignore LengthCompare::operator();
+%inline %{
+struct LengthCompare {
+ bool operator() (std::string s1, std::string s2) const {
+ return s1.size() < s2.size();
+ }
+};
+%}
+// A map sorted by string lengths
+%template(StringLengthNumberMap) std::map< std::string, int, LengthCompare >;
+
+%inline %{
+std::map< std::string, int, LengthCompare > MyMap;
+void populate(std::map< std::string, int, LengthCompare >&m) {
+ m["aa"] = 2;
+ m["xxxx"] = 4;
+ m["a"] = 1;
+ m["aaaaa"] = 5;
+ m["zzz"] = 3;
+}
+%}
diff --git a/Examples/test-suite/python/li_std_map_runme.py b/Examples/test-suite/python/li_std_map_runme.py
index 5b5e8f1..ac214dd 100644
--- a/Examples/test-suite/python/li_std_map_runme.py
+++ b/Examples/test-suite/python/li_std_map_runme.py
@@ -67,3 +67,15 @@
raise RuntimeError("itervalues")
if [i for i in mii.iteritems()] != [(1, 2)]:
raise RuntimeError("iteritems")
+
+
+slmap = li_std_map.StringLengthNumberMap()
+li_std_map.populate(slmap)
+
+keys = " ".join([k for k in slmap.keys()])
+if keys != "a aa zzz xxxx aaaaa":
+ raise RuntimeError("Keys are wrong or in wrong order: " + keys)
+
+values = " ".join([str(v) for v in slmap.values()])
+if values != "1 2 3 4 5":
+ raise RuntimeError("Values are wrong or in wrong order: " + values)