diff --git a/Examples/test-suite/csharp/li_std_set_runme.cs b/Examples/test-suite/csharp/li_std_set_runme.cs index 6519e8c8d..0e353c46d 100644 --- a/Examples/test-suite/csharp/li_std_set_runme.cs +++ b/Examples/test-suite/csharp/li_std_set_runme.cs @@ -85,5 +85,12 @@ public class runme ss = new StringSet{"foo", "bar", "baz"}; ss.UnionWith(new[] {"baz", "quux"}); checkThat(ss.SetEquals(new[] {"foo", "bar", "baz", "quux"}), "UnionWith works"); + + // Check a set of another type. + FooSet fooSet = new FooSet(); + ISet fooISet = fooSet; + checkThat(fooISet.Count == 0, "is initially empty"); + checkThat(fooISet.Add(new Foo(17)), "added successfully"); + checkThat(fooISet.Count == 1, "is not empty any more"); } } diff --git a/Examples/test-suite/java/li_std_set_runme.java b/Examples/test-suite/java/li_std_set_runme.java index 9763484c2..017908c21 100644 --- a/Examples/test-suite/java/li_std_set_runme.java +++ b/Examples/test-suite/java/li_std_set_runme.java @@ -71,5 +71,11 @@ public class li_std_set_runme { checkThat(ss.removeAll(found)); checkThat(ss.isEmpty()); checkThat(ss.size() == 0); + + // Check a set of another type. + java.util.AbstractSet fooSet = new FooSet(); + checkThat(fooSet.isEmpty()); + checkThat(fooSet.add(new Foo(17))); + checkThat(fooSet.size() == 1); } } diff --git a/Examples/test-suite/li_std_set.i b/Examples/test-suite/li_std_set.i index bb952cd85..45eda51ff 100644 --- a/Examples/test-suite/li_std_set.i +++ b/Examples/test-suite/li_std_set.i @@ -23,7 +23,25 @@ %template(v_int) std::vector; %template(set_string) std::set; #elif defined(SWIGJAVA) || defined(SWIGCSHARP) + // This operator is only defined because it's needed to store objects of + // type Foo in std::set in C++, we don't need to wrap it. + %ignore operator<; + %inline %{ + struct Foo + { + explicit Foo(int n) : n(n) {} + + int n; + + friend bool operator<(Foo foo1, Foo foo2) + { + return foo1.n < foo2.n; + } + }; + %} + %template(StringSet) std::set; + %template(FooSet) std::set; #endif #if defined(SWIGRUBY) diff --git a/Lib/csharp/std_set.i b/Lib/csharp/std_set.i index 3b2492e0e..1d946e644 100644 --- a/Lib/csharp/std_set.i +++ b/Lib/csharp/std_set.i @@ -30,7 +30,7 @@ class set { %typemap(csinterfaces) std::set "global::System.IDisposable, global::System.Collections.Generic.ISet<$typemap(cstype, T)>\n"; %proxycode %{ - void global::System.Collections.Generic.ICollection<$typemap(cstype, T)>.Add(string item) { + void global::System.Collections.Generic.ICollection<$typemap(cstype, T)>.Add($typemap(cstype, T) item) { ((global::System.Collections.Generic.ISet<$typemap(cstype, T)>)this).Add(item); }