Improve backwards compatibility in D std::vector wrappers
For users who have typemaps for the parameters in the setElement method.
Correct definitions of const_reference to match the those in the
(C++11) standard.
diff --git a/Lib/d/std_vector.i b/Lib/d/std_vector.i
index 9dcb184..fb8f7d2 100644
--- a/Lib/d/std_vector.i
+++ b/Lib/d/std_vector.i
@@ -135,7 +135,7 @@
return $self->capacity() - $self->size();
}
- CONST_REFERENCE remove() throw (std::out_of_range) {
+ const_reference remove() throw (std::out_of_range) {
if ($self->empty()) {
throw std::out_of_range("Tried to remove last element from empty vector.");
}
@@ -145,7 +145,7 @@
return value;
}
- CONST_REFERENCE remove(size_type index) throw (std::out_of_range) {
+ const_reference remove(size_type index) throw (std::out_of_range) {
if (index >= $self->size()) {
throw std::out_of_range("Tried to remove element with invalid index.");
}
@@ -160,7 +160,7 @@
// Wrappers for setting/getting items with the possibly thrown exception
// specified (important for SWIG wrapper generation).
%extend {
- CONST_REFERENCE getElement(size_type index) throw (std::out_of_range) {
+ const_reference getElement(size_type index) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to get value of element with invalid index.");
}
@@ -172,11 +172,11 @@
// generation issue when using const pointers as vector elements (like
// std::vector< const int* >).
%extend {
- void setElement(size_type index, CTYPE const& value) throw (std::out_of_range) {
+ void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to set value of element with invalid index.");
}
- (*$self)[index] = value;
+ (*$self)[index] = val;
}
}
@@ -478,7 +478,7 @@
return pv;
}
- CONST_REFERENCE remove() throw (std::out_of_range) {
+ const_reference remove() throw (std::out_of_range) {
if ($self->empty()) {
throw std::out_of_range("Tried to remove last element from empty vector.");
}
@@ -488,7 +488,7 @@
return value;
}
- CONST_REFERENCE remove(size_type index) throw (std::out_of_range) {
+ const_reference remove(size_type index) throw (std::out_of_range) {
if (index >= $self->size()) {
throw std::out_of_range("Tried to remove element with invalid index.");
}
@@ -520,7 +520,7 @@
// Wrappers for setting/getting items with the possibly thrown exception
// specified (important for SWIG wrapper generation).
%extend {
- CONST_REFERENCE getElement(size_type index) throw (std::out_of_range) {
+ const_reference getElement(size_type index) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to get value of element with invalid index.");
}
@@ -531,11 +531,11 @@
// generation issue when using const pointers as vector elements (like
// std::vector< const int* >).
%extend {
- void setElement(size_type index, CTYPE const& value) throw (std::out_of_range) {
+ void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) {
if ((index < 0) || ($self->size() <= index)) {
throw std::out_of_range("Tried to set value of element with invalid index.");
}
- (*$self)[index] = value;
+ (*$self)[index] = val;
}
}
@@ -558,7 +558,7 @@
%define SWIG_STD_VECTOR_ENHANCED(CTYPE...)
namespace std {
template<> class vector<CTYPE > {
- SWIG_STD_VECTOR_MINIMUM_INTERNAL(%arg(CTYPE const&), %arg(CTYPE))
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, %arg(CTYPE))
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE)
};
}
@@ -573,11 +573,11 @@
// primary (unspecialized) class template for std::vector
// does not require operator== to be defined
template<class T> class vector {
- SWIG_STD_VECTOR_MINIMUM_INTERNAL(T const&, T)
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, T)
};
// specializations for pointers
template<class T> class vector<T *> {
- SWIG_STD_VECTOR_MINIMUM_INTERNAL(T *const&, T *)
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, T *)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *)
};
// bool is a bit different in the C++ standard - const_reference in particular