Fixes removeFirst() and removeLast() incompatibilities with methods
of the same name in the Java base class java.util.AbstractSequentialList
which were added in JDK 21 as part of JEP-431.
configure.ac has been modified to detect the version of JDK/Java for use
in testing the test-suite via the JAVA_VERSION_MAJOR variable.
Needed to continue testing removeFirst(), removeLast(), addFirst(), addLast().
Closes#3156
std::vector::capacity and std::vector::reserve signature changes.
Java api changes from:
public long capacity() { ... }
public void reserve(long n) { ... }
to:
public int capacity() { ... }
public void reserve(int n) { ... }
to fit in with the usual Java convention of using int for container
indexing and sizing.
The original api for std::vector::reserve can be also be made available via
%extend to add in an overloaded method as follows:
%include <std_vector.i>
%extend std::vector {
void reserve(jlong n) throw (std::length_error, std::out_of_range) {
if (n < 0)
throw std::out_of_range("vector reserve size must be positive");
self->reserve(n);
}
}
This change is partially driven by the need to seamlessly support the full
64-bit range for size_t generically, apart from the customisations for the
STL containers, by using:
%apply unsigned long long { size_t };
%apply const unsigned long long & { const size_t & };
Similarly for std::array::size.
Also enhance docs for applying unsigned long long typemaps for 64-bit
size_t.
The std::vector wrappers have been changed to work by default for elements that are
not default insertable, i.e. have no default constructor. This has been achieved by
not wrapping:
vector(size_type n);
Previously the above had to be ignored via %ignore.
If the above constructor is still required it can be added back in again via %extend:
%extend std::vector {
vector(size_type count) { return new std::vector< T >(count); }
}
Alternatively, the following wrapped constructor could be used as it provides near-enough
equivalent functionality:
vector(jint count, const value_type& value);
The equivalent change to std::list has also been made (std::list
wrappers were not in the previous release [3.0.12] though).
- Add missing vector copy constructor
- Add constructor to initialize the containers. Note that Java's
equivalent constructor for ArrayList just sets the capacity, whereas
the wrappers behave like the C++ constructor and set the size. I've
done this mainly because there has been a vector(size_type) constructor
in the Java wrappers for many years, so best to keep this unchanged.