Skip to content

Commit e71ef1d

Browse files
committed
Use common routines for set, multiset
Allows downstream specialization as well
1 parent 6b9ea45 commit e71ef1d

File tree

2 files changed

+18
-39
lines changed

2 files changed

+18
-39
lines changed

Lib/fortran/std_multiset.i

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,13 @@
55
* keys.
66
* ------------------------------------------------------------------------- */
77

8-
%include "std_common.i"
9-
10-
%{
11-
#include <set>
12-
%}
13-
14-
%fortransubroutine std::multiset::erase;
8+
%include "std_set.i"
159

1610
namespace std {
17-
1811
template<class _Key, class _Compare = std::less<_Key>, class _Alloc = std::allocator<_Key> >
1912
class multiset {
20-
public:
21-
typedef _Key value_type;
22-
typedef _Key key_type;
23-
typedef std::size_t size_type;
24-
typedef ptrdiff_t difference_type;
25-
typedef value_type *pointer;
26-
typedef const value_type *const_pointer;
27-
typedef value_type &reference;
28-
typedef const value_type &const_reference;
29-
typedef _Alloc allocator_type;
30-
31-
public:
32-
set();
33-
34-
// - Use native Fortran integers in proxy code
35-
%apply int FORTRAN_INT {size_type};
36-
37-
bool empty() const;
38-
size_type size() const;
39-
void clear();
40-
size_type erase(const key_type& x);
41-
size_type count(const key_type& x) const;
42-
void insert(const_reference x);
13+
SWIG_STD_SET_COMMON(multiset, _Key, _Compare, _Alloc)
4314
};
44-
} // namespace std
15+
} // end namespace std
16+
4517

Lib/fortran/std_set.i

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
#include <set>
99
%}
1010

11-
%fortransubroutine std::set::erase;
11+
%define SWIG_STD_SET_COMMON(CLASS, _Key, _Compare, _Alloc)
1212

13-
namespace std {
14-
15-
template<class _Key, class _Compare = std::less<_Key>, class _Alloc = std::allocator<_Key> >
16-
class set {
1713
public:
14+
// Typedefs
1815
typedef _Key value_type;
1916
typedef _Key key_type;
2017
typedef std::size_t size_type;
@@ -26,17 +23,27 @@ public:
2623
typedef _Alloc allocator_type;
2724

2825
public:
29-
set();
26+
CLASS();
3027

3128
// - Use native Fortran integers in proxy code
3229
%apply int FORTRAN_INT {size_type};
3330

3431
bool empty() const;
3532
size_type size() const;
3633
void clear();
34+
35+
%fortransubroutine erase;
36+
3737
size_type erase(const key_type& x);
3838
size_type count(const key_type& x) const;
3939
void insert(const_reference x);
40+
41+
%enddef
42+
43+
namespace std {
44+
template<class _Key, class _Compare = std::less<_Key>, class _Alloc = std::allocator<_Key> >
45+
class set {
46+
SWIG_STD_SET_COMMON(set, _Key, _Compare, _Alloc)
4047
};
48+
} // end namespace std
4149

42-
} // namespace std

0 commit comments

Comments
 (0)