21
21
* Macro definitions
22
22
* ------------------------------------------------------------------------- */
23
23
24
- %define %flc_set_algorithm(FUNCNAME)
25
- %inline {
26
- template <class Set_t >
27
- static Set_t FUNCNAME (const Set_t& left, const Set_t& right)
28
- {
29
- Set_t result;
30
- std::FUNCNAME (left.begin (), left.end (),
31
- right.begin (), right.end (),
32
- std::inserter (result, result.end ()));
33
- return result;
34
- }
35
- }
36
-
37
- %template (FUNCNAME) FUNCNAME<std::set<int > >;
38
- %template (FUNCNAME) FUNCNAME<std::set<std::string> >;
24
+ %define %flc_define_set_algorithm(FUNCNAME)
25
+ %insert(" header" ) {
26
+ template <class Set_t >
27
+ static Set_t flc_##FUNCNAME (const Set_t& left, const Set_t& right)
28
+ {
29
+ Set_t result;
30
+ std::FUNCNAME (left.begin (), left.end (),
31
+ right.begin (), right.end (),
32
+ std::inserter (result, result.end ()));
33
+ return result;
34
+ }
35
+ } // end %insert
36
+ %enddef
39
37
38
+ %define %flc_extend_set_algorithm(FUNCNAME, RETVAL, TYPE)
39
+ // The rename with the stringifying macro is necessary because 'union' is a
40
+ // keyword.
41
+ %rename(#FUNCNAME) std::set<TYPE>::set_##FUNCNAME;
42
+ %extend std::set<TYPE> {
43
+ RETVAL set_##FUNCNAME (const std::set<TYPE>& other)
44
+ { return flc_set_##FUNCNAME (*$self, other); }
45
+ } // end %extend
40
46
%enddef
41
47
42
48
%define %flc_extend_set_pod(CTYPE)
@@ -52,7 +58,6 @@ static Set_t FUNCNAME(const Set_t& left, const Set_t& right)
52
58
void insert (const CTYPE* DATA, size_type SIZE) {
53
59
$self->insert (DATA, DATA + SIZE);
54
60
}
55
-
56
61
%enddef
57
62
58
63
/* ------------------------------------------------------------------------- */
@@ -83,10 +88,37 @@ namespace std {
83
88
}
84
89
%enddef
85
90
91
+ /* -------------------------------------------------------------------------
92
+ * Algorithms
93
+ * ------------------------------------------------------------------------- */
94
+
95
+ %flc_define_set_algorithm(set_difference)
96
+ %flc_define_set_algorithm(set_intersection)
97
+ %flc_define_set_algorithm(set_symmetric_difference)
98
+ %flc_define_set_algorithm(set_union)
99
+
100
+ %insert(" header" ) %{
101
+ template <class Set_t >
102
+ static bool flc_set_includes (const Set_t& left, const Set_t& right)
103
+ {
104
+ return std::includes (left.begin (), left.end (),
105
+ right.begin (), right.end ());
106
+ }
107
+ %}
108
+
109
+ %define %flc_extend_algorithms(TYPE)
110
+ %flc_extend_set_algorithm(difference, std::set<TYPE >, TYPE)
111
+ %flc_extend_set_algorithm(intersection, std::set<TYPE >, TYPE)
112
+ %flc_extend_set_algorithm(symmetric_difference, std::set<TYPE >, TYPE)
113
+ %flc_extend_set_algorithm(union , std::set<TYPE >, TYPE)
114
+ %flc_extend_set_algorithm(includes, bool , TYPE)
115
+ %enddef
116
+
86
117
/* -------------------------------------------------------------------------
87
118
* Numeric sets
88
119
* ------------------------------------------------------------------------- */
89
120
121
+ %flc_extend_algorithms(int )
90
122
%specialize_std_set_pod(int )
91
123
92
124
%template (SetInt) std::set<int >;
@@ -106,26 +138,5 @@ namespace std {
106
138
107
139
%include <std_string.i>
108
140
%import " flc_string.i"
141
+ %flc_extend_algorithms(std::string)
109
142
%template (SetString) std::set<std::string>;
110
-
111
- /* -------------------------------------------------------------------------
112
- * Algorithms
113
- * ------------------------------------------------------------------------- */
114
-
115
- %flc_set_algorithm(set_difference)
116
- %flc_set_algorithm(set_intersection)
117
- %flc_set_algorithm(set_symmetric_difference)
118
- %flc_set_algorithm(set_union)
119
-
120
- %inline %{
121
- template <class Set_t >
122
- static bool includes (const Set_t& left, const Set_t& right)
123
- {
124
- return std::includes (left.begin (), left.end (),
125
- right.begin (), right.end ());
126
- }
127
- %}
128
-
129
- %template (includes) includes<std::set<int > >;
130
- %template (includes) includes<std::set<std::string> >;
131
-
0 commit comments