Test code for removed methods from std::list for compatibility with java.util.List

This commit is contained in:
William S Fulton 2025-04-03 09:07:50 +01:00
parent 34b71a3bba
commit 124d8a8c37
1 changed files with 31 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#include <numeric>
%}
#if 1
#if defined(SWIGJAVA) && JAVA_VERSION_MAJOR < 21
// Test these methods which were removed in swig-4.0 as JDK added the same methods
// in the java.util.AbstractSequentialList base but unfortunately two of them use
@ -20,6 +21,36 @@
void addFirst(const T &value) { $self->push_front(value); }
}
#endif
#else
// Alternative implementation suggested in https://github.com/swig/swig/issues/3156
%extend std::list {
%proxycode %{
public $typemap(jboxtype, T) removeLast() {
if (this.isEmpty()) {
throw new java.util.NoSuchElementException();
} else {
return this.remove(this.size() - 1);
}
}
public $typemap(jboxtype, T) removeFirst() {
if (this.isEmpty()) {
throw new java.util.NoSuchElementException();
} else {
return this.remove(0);
}
}
public void addLast($typemap(jboxtype, T) value) {
this.add(value);
}
public void addFirst($typemap(jboxtype, T) value) {
this.add(0, value);
}
%}
}
#endif
%template(BoolList) std::list<bool>;
%template(CharList) std::list<char>;