Add support for std::map<> comparator template argument for Java

Allow exporting maps using non-default comparison function, similar to
what was done for C# back in 9efaf954c7
This commit is contained in:
Vadim Zeitlin 2018-06-09 18:02:42 +02:00
commit 369be6fac4
2 changed files with 8 additions and 5 deletions

View file

@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress) Version 4.0.0 (in progress)
=========================== ===========================
2018-06-09: vadz
[Java] Allow exporting std::map using non-default comparison function.
2018-06-08: philippkraft 2018-06-08: philippkraft
[Python] Stop exposing <CLASS>_swigregister to Python. It's not [Python] Stop exposing <CLASS>_swigregister to Python. It's not
useful for user Python code to call this, and it just clutters the useful for user Python code to call this, and it just clutters the

View file

@ -18,21 +18,21 @@
namespace std { namespace std {
template<class K, class T> class map { template<class K, class T, class C = std::less<K> > class map {
public: public:
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef K key_type; typedef K key_type;
typedef T mapped_type; typedef T mapped_type;
map(); map();
map(const map<K,T> &); map(const map<K,T,C> &);
unsigned int size() const; unsigned int size() const;
bool empty() const; bool empty() const;
void clear(); void clear();
%extend { %extend {
const T& get(const K& key) throw (std::out_of_range) { const T& get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key); std::map<K,T,C >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
return i->second; return i->second;
else else
@ -42,14 +42,14 @@ namespace std {
(*self)[key] = x; (*self)[key] = x;
} }
void del(const K& key) throw (std::out_of_range) { void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key); std::map<K,T,C >::iterator i = self->find(key);
if (i != self->end()) if (i != self->end())
self->erase(i); self->erase(i);
else else
throw std::out_of_range("key not found"); throw std::out_of_range("key not found");
} }
bool has_key(const K& key) { bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key); std::map<K,T,C >::iterator i = self->find(key);
return i != self->end(); return i != self->end();
} }
} }