Replace leftover string with the proper type in C# set typemap
This is just a mistake remaining from generalizing the old string-specific typemap to any type. Fix it now and update a unit test to test for sets of objects other than strings.
This commit is contained in:
parent
2db6b42715
commit
53d75dc133
4 changed files with 32 additions and 1 deletions
|
|
@ -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<Foo> 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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Foo> fooSet = new FooSet();
|
||||
checkThat(fooSet.isEmpty());
|
||||
checkThat(fooSet.add(new Foo(17)));
|
||||
checkThat(fooSet.size() == 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,25 @@
|
|||
%template(v_int) std::vector<int>;
|
||||
%template(set_string) std::set<std::string>;
|
||||
#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<std::string>;
|
||||
%template(FooSet) std::set<Foo>;
|
||||
#endif
|
||||
|
||||
#if defined(SWIGRUBY)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class set {
|
|||
|
||||
%typemap(csinterfaces) std::set<T> "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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue