Skip to content

Commit 0e44905

Browse files
committed
Add optional result for insertion in std::set
1 parent f9ce804 commit 0e44905

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

Examples/test-suite/fortran/li_std_set_runme.F90

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@ subroutine test_set_string
5252
use li_std_set, only : set_string
5353
implicit none
5454
type(set_string) :: s
55+
logical :: inserted = .false.
5556

5657
s = set_string()
5758
ASSERT(s%empty())
5859

5960
call s%insert("yoohoo")
60-
call s%insert("howdy")
61+
call s%insert("howdy", inserted)
62+
ASSERT(inserted .eqv. .true.)
6163
ASSERT(s%size() == 2)
6264
ASSERT(s%count("yoohoo") == 1)
6365
ASSERT(s%count("hiya") == 0)
6466

65-
call s%insert("howdy")
67+
call s%insert("howdy", inserted)
68+
ASSERT(inserted .eqv. .false.)
6669
ASSERT(s%count("howdy") == 1)
6770
ASSERT(s%size() == 2)
6871

Lib/fortran/std_multiset.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
%define %swig_std_multiset(_Key, _Compare, _Alloc)
1111
%swig_std_setcommon(multiset, _Key, _Compare, _Alloc)
12+
13+
void insert(const_reference x);
1214
%enddef
1315

1416
namespace std {

Lib/fortran/std_set.i

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ public:
3737

3838
size_type erase(const key_type& x);
3939
size_type count(const key_type& x) const;
40-
void insert(const_reference x);
4140
%enddef
4241

4342
%define %swig_std_set(_Key, _Compare, _Alloc)
4443
%swig_std_setcommon(set, _Key, _Compare, _Alloc)
44+
45+
%fortransubroutine insert;
46+
47+
%extend {
48+
bool insert(const_reference x) {
49+
std::pair<std::set<_Key, _Compare, _Alloc >::iterator, bool> result = $self->insert(x);
50+
return result.second;
51+
}
52+
}
4553
%enddef
4654

4755
namespace std {

0 commit comments

Comments
 (0)