diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index 8c2f889c6..9ec8ad060 100755 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -170,6 +170,7 @@ public: typedef size_t size_type; typedef CTYPE value_type; + typedef const value_type& const_reference; %rename(Clear) clear; void clear(); %rename(Add) push_back; @@ -197,7 +198,7 @@ else throw std::out_of_range("index"); } - const value_type& getitem(int index) throw (std::out_of_range) { + const_reference getitem(int index) throw (std::out_of_range) { if (index>=0 && index<(int)self->size()) return (*self)[index]; else diff --git a/Lib/java/std_vector.i b/Lib/java/std_vector.i index fb945d986..3aa85929a 100644 --- a/Lib/java/std_vector.i +++ b/Lib/java/std_vector.i @@ -1,66 +1,36 @@ -// -// SWIG typemaps for std::vector -// Luigi Ballabio -// May 7, 2002 -// -// Java implementation - %include -// ------------------------------------------------------------------------ -// std::vector -// -// The aim of all that follows would be to integrate std::vector with -// Java as much as possible, namely, to allow the user to pass and -// be returned Java (arrays? containers?) -// const declarations are used to guess the intent of the function being -// exported; therefore, the following rationale is applied: -// -// -- f(std::vector), f(const std::vector&), f(const std::vector*): -// the parameter being read-only, either a Java sequence or a -// previously wrapped std::vector can be passed. -// -- f(std::vector&), f(std::vector*): -// the parameter must be modified; therefore, only a wrapped std::vector -// can be passed. -// -- std::vector f(): -// the vector is returned by copy; therefore, a Java sequence of T:s -// is returned which is most easily used in other Java functions -// -- std::vector& f(), std::vector* f(), const std::vector& f(), -// const std::vector* f(): -// the vector is returned by reference; therefore, a wrapped std::vector -// is returned -// ------------------------------------------------------------------------ - %{ #include -#include #include %} -// exported class - namespace std { template class vector { - // add generic typemaps here public: + typedef size_t size_type; + typedef T value_type; + typedef const value_type& const_reference; vector(); - vector(unsigned int); - unsigned int size() const; + vector(size_type n); + size_type size() const; + size_type capacity() const; + void reserve(size_type n); %rename(isEmpty) empty; bool empty() const; void clear(); %rename(add) push_back; - void push_back(const T& x); + void push_back(const value_type& x); %extend { - T& get(int i) throw (std::out_of_range) { + const_reference get(int i) throw (std::out_of_range) { int size = int(self->size()); if (i>=0 && isize()); if (i>=0 && i class vector { - // add specialized typemaps here - public: - vector(); - vector(unsigned int); - unsigned int size() const; - %rename(isEmpty) empty; - bool empty() const; - void clear(); - %rename(add) push_back; - void push_back(T x); - %extend { - T get(int i) throw (std::out_of_range) { - int size = int(self->size()); - if (i>=0 && isize()); - if (i>=0 && i