Skip to content

Commit

Permalink
C++11 support for new versions of erase and insert in the STL contain…
Browse files Browse the repository at this point in the history
…ers.

The erase and insert methods in the containers use const_iterator instead
of iterator in C++11.  There are times when the methods wrapped must match
the parameters exactly. Specifically when full type information for
template types is missing or SWIG fails to look up the type correctly,
for example:

  %include <std_vector.i>
  typedef float Real;
  %template(RealVector) std::vector<Real>;

SWIG does not find std::vector<Real>::iterator because %template using
typedefs does not always work and so SWIG doesn't know if the type is
copyable and so uses SwigValueWrapper<iterator> which does
not support conversion to another type (const_iterator). This resulted
in compilation errors when using the C++11 version of the containers.

Closes #73

Conflicts:

	CHANGES.current
	Lib/std/std_unordered_map.i
	Lib/std/std_unordered_set.i
  • Loading branch information
wsfulton committed Feb 8, 2014
1 parent 7b5eb19 commit acc5a5e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
21 changes: 21 additions & 0 deletions CHANGES.current
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.12 (9 Feb 2014)
===========================

2013-12-22: wsfulton
C++11 support for new versions of erase and insert in the STL containers.

The erase and insert methods in the containers use const_iterator instead
of iterator in C++11. There are times when the methods wrapped must match
the parameters exactly. Specifically when full type information for
template types is missing or SWIG fails to look up the type correctly,
for example:

%include <std_vector.i>
typedef float Real;
%template(RealVector) std::vector<Real>;

SWIG does not find std::vector<Real>::iterator because %template using
typedefs does not always work and so SWIG doesn't know if the type is
copyable and so uses SwigValueWrapper<iterator> which does
not support conversion to another type (const_iterator). This resulted
in compilation errors when using the C++11 version of the containers.

Closes #73

2013-10-17: wsfulton
[R] Fix SF #1340 - Visual Studio compile error in C++ wrappers due to #include <exception>
within extern "C" block.
Expand Down
21 changes: 15 additions & 6 deletions Lib/std/std_container.i
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@
void resize(size_type new_size);

#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator erase(iterator pos);
iterator erase(iterator first, iterator last);
%extend {
// %extend wrapper used for differing definitions of these methods introduced in C++11
iterator erase(iterator pos) { return $self->erase(pos); }
iterator erase(iterator first, iterator last) { return $self->erase(first, last); }
}
#endif

%enddef
Expand All @@ -68,8 +71,11 @@
void resize(size_type new_size, const value_type& x);

#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator insert(iterator pos, const value_type& x);
void insert(iterator pos, size_type n, const value_type& x);
%extend {
// %extend wrapper used for differing definitions of these methods introduced in C++11
iterator insert(iterator pos, const value_type& x) { return $self->insert(pos, x); }
void insert(iterator pos, size_type n, const value_type& x) { $self->insert(pos, n, x); }
}
#endif

%enddef
Expand All @@ -89,8 +95,11 @@
void resize(size_type new_size, value_type x);

#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator insert(iterator pos, value_type x);
void insert(iterator pos, size_type n, value_type x);
%extend {
// %extend wrapper used for differing definitions of these methods introduced in C++11
iterator insert(iterator pos, value_type x) { return $self->insert(pos, x); }
void insert(iterator pos, size_type n, value_type x) { $self->insert(pos, n, x); }
}
#endif

%enddef
Expand Down
8 changes: 5 additions & 3 deletions Lib/std/std_map.i
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
size_type count(const key_type& x) const;

#ifdef SWIG_EXPORT_ITERATOR_METHODS
// iterator insert(iterator position, const value_type& x);
void erase(iterator position);
void erase(iterator first, iterator last);
%extend {
// %extend wrapper used for differing definitions of these methods introduced in C++11
void erase(iterator position) { $self->erase(position); }
void erase(iterator first, iterator last) { $self->erase(first, last); }
}

iterator find(const key_type& x);
iterator lower_bound(const key_type& x);
Expand Down
7 changes: 5 additions & 2 deletions Lib/std/std_set.i
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
reverse_iterator rbegin();
reverse_iterator rend();

void erase(iterator pos);
void erase(iterator first, iterator last);
%extend {
// %extend wrapper used for differing definitions of these methods introduced in C++11
void erase(iterator pos) { $self->erase(pos); }
void erase(iterator first, iterator last) { $self->erase(first, last); }
}

iterator find(const key_type& x);
iterator lower_bound(const key_type& x);
Expand Down

0 comments on commit acc5a5e

Please sign in to comment.