Skip to content

Commit 8044e01

Browse files
authored
Merge pull request #145 from swig-fortran/std-set
Update std::set to look more like std::vector
2 parents 4b47d30 + e71ef1d commit 8044e01

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

Examples/test-suite/fortran/li_std_set_runme.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ subroutine test_multiset_int
1616
use li_std_set, only : multiset_int => set_int
1717
implicit none
1818
type(multiset_int) :: s
19-
integer(c_size_t) :: num_erased
19+
integer :: num_erased
2020

2121
s = multiset_int()
2222
ASSERT(s%empty())

Lib/fortran/std_multiset.i

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

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

1410
namespace std {
15-
1611
template<class _Key, class _Compare = std::less<_Key>, class _Alloc = std::allocator<_Key> >
1712
class multiset {
18-
public:
19-
typedef _Key value_type;
20-
typedef _Key key_type;
21-
typedef std::size_t size_type;
22-
typedef ptrdiff_t difference_type;
23-
typedef value_type *pointer;
24-
typedef const value_type *const_pointer;
25-
typedef value_type &reference;
26-
typedef const value_type &const_reference;
27-
typedef _Alloc allocator_type;
28-
29-
public:
30-
set();
31-
32-
bool empty() const;
33-
size_type size() const;
34-
void clear();
35-
size_type erase(const key_type& x);
36-
size_type count(const key_type& x) const;
37-
void insert(const_reference x);
13+
SWIG_STD_SET_COMMON(multiset, _Key, _Compare, _Alloc)
3814
};
39-
} // namespace std
15+
} // end namespace std
16+
4017

Lib/fortran/std_set.i

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
* std_set.i
33
* ------------------------------------------------------------------------- */
44

5+
%include "std_common.i"
6+
57
%{
68
#include <set>
79
%}
810

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

13-
template<class _Key, class _Compare = std::less<_Key>, class _Alloc = std::allocator<_Key> >
14-
class set {
1513
public:
14+
// Typedefs
1615
typedef _Key value_type;
1716
typedef _Key key_type;
1817
typedef std::size_t size_type;
@@ -24,14 +23,27 @@ public:
2423
typedef _Alloc allocator_type;
2524

2625
public:
27-
set();
26+
CLASS();
27+
28+
// - Use native Fortran integers in proxy code
29+
%apply int FORTRAN_INT {size_type};
2830

2931
bool empty() const;
3032
size_type size() const;
3133
void clear();
34+
35+
%fortransubroutine erase;
36+
3237
size_type erase(const key_type& x);
3338
size_type count(const key_type& x) const;
3439
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)
3547
};
48+
} // end namespace std
3649

37-
} // namespace std

0 commit comments

Comments
 (0)