2121 * Macro definitions
2222 * ------------------------------------------------------------------------- */
2323
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
3937
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
4046%enddef
4147
4248%define %flc_extend_set_pod(CTYPE)
@@ -52,7 +58,6 @@ static Set_t FUNCNAME(const Set_t& left, const Set_t& right)
5258 void insert (const CTYPE* DATA, size_type SIZE) {
5359 $self->insert (DATA, DATA + SIZE);
5460 }
55-
5661%enddef
5762
5863/* ------------------------------------------------------------------------- */
@@ -83,10 +88,37 @@ namespace std {
8388}
8489%enddef
8590
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+
86117/* -------------------------------------------------------------------------
87118 * Numeric sets
88119 * ------------------------------------------------------------------------- */
89120
121+ %flc_extend_algorithms(int )
90122%specialize_std_set_pod(int )
91123
92124%template (SetInt) std::set<int >;
@@ -106,26 +138,5 @@ namespace std {
106138
107139%include <std_string.i>
108140%import " flc_string.i"
141+ %flc_extend_algorithms(std::string)
109142%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