Debian Codegraph @

sigc++/functors/mem_fun.h

raw symbols SCIP
1 /*
2 * Copyright 2003 - 2016, The libsigc++ Development Team
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #ifndef SIGC_FUNCTORS_MEM_FUN_H
20 #define SIGC_FUNCTORS_MEM_FUN_Hcxx . . $ `sigc++/functors/mem_fun.h:20:9`!
21 #include <sigc++/type_traits.h>cxx . . $ `<file>/sigc++/type_traits.h`/
22 #include <sigc++/limit_reference.h>cxx . . $ `<file>/sigc++/limit_reference.h`/
23 #include <sigc++/member_method_trait.h>cxx . . $ `<file>/sigc++/member_method_trait.h`/
24 #include <functional>
25 #include <utility>
26
27 // implementation notes:
28 // - we do not use bind here, because it would introduce
29 // an extra copy and complicate the header include order if bind is
30 // to have automatic conversion for member pointers.
31
32 namespace sigccxx . . $ sigc/
33 {
34
35 /** @defgroup mem_fun mem_fun()
36 * %mem_fun() creates a functor from a pointer to a method.
37 *
38 * Optionally, a reference to an object can be bound to the functor.
39 *
40 * @note If the object type inherits from sigc::trackable, and the
41 * functor returned from %mem_fun() is assigned to
42 * a @ref sigc::slot<T_return(T_arg...)> "sigc::slot", the functor
43 * will be automatically cleared when the object goes out of scope. Invoking
44 * that slot will then have no effect and will not try to use the destroyed
45 * instance.
46 *
47 * @par Example:
48 * @code
49 * struct foo : public sigc::trackable
50 * {
51 * void bar(int) {}
52 * };
53 * foo my_foo;
54 * sigc::slot<void(int)> sl = sigc::mem_fun(my_foo, &foo::bar);
55 * // Note: f is not a slot. It will not be invalidated when my_foo is deleted.
56 * auto f = sigc::mem_fun(my_foo, &foo::bar); // Usually not what you want.
57 * @endcode
58 *
59 * For const methods %mem_fun() takes a const reference or pointer to an object.
60 *
61 * @par Example:
62 * @code
63 * struct foo : public sigc::trackable
64 * {
65 * void bar(int) const {}
66 * };
67 * const foo my_foo;
68 * sigc::slot<void(int)> sl = sigc::mem_fun(my_foo, &foo::bar);
69 * @endcode
70 *
71 * If the member function pointer is to an overloaded type, you must specify
72 * the types using template arguments.
73 *
74 * @par Example:
75 * @code
76 * struct foo : public sigc::trackable
77 * {
78 * void bar(int) {} // choose this one
79 * void bar(float) {}
80 * void bar(int, int) {}
81 * };
82 * foo my_foo;
83 * sigc::slot<void(int)> sl = sigc::mem_fun1<void, foo, foo, int>(my_foo, &foo::bar);
84 * @endcode
85 *
86 * @ingroup sigcfunctors
87 */
88
89 template<typename T_func, typename... T_arg>
90 class mem_functorcxx . . $ sigc/mem_functor#
91 {
92 public:
93 using object_typecxx . . $ sigc/mem_functor#object_type# = typename internalcxx . . $ sigc/internal/::member_method_classcxx . . $ sigc/internal/member_method_class#<T_func>::type;
94
95 using function_typecxx . . $ sigc/mem_functor#function_type# = T_func;
96
97 using obj_type_with_modifiercxx . . $ sigc/mem_functor#obj_type_with_modifier# = typename stdcxx . . $ std/::
98 conditional_t<internalcxx . . $ sigc/internal/::member_method_is_constcxx . . $ sigc/internal/member_method_is_const#<T_func>::value, const object_typecxx . . $ sigc/mem_functor#object_type#, object_typecxx . . $ sigc/mem_functor#object_type#>;
99
100 /// Constructs an invalid functor.
101 mem_functorcxx . . $ sigc/mem_functor#`mem_functor<T_func, T_arg...>`(49f6e7a06ebc5aa8).() : func_ptr_cxx . . $ sigc/mem_functor#func_ptr_.(nullptr) {}
102
103 /** Constructs a mem_functor object that wraps the passed method.
104 * @param func Pointer to method will be invoked from operator()().
105 */
106 explicit mem_functorcxx . . $ sigc/mem_functor#`mem_functor<T_func, T_arg...>`(9b289cee16747614).(function_typecxx . . $ sigc/mem_functor#function_type# func) : func_ptr_cxx . . $ sigc/mem_functor#func_ptr_.(func) {}
107
108 /** Execute the wrapped method operating on the passed instance.
109 * @param obj Reference to instance the method should operate on.
110 * @param a Arguments to be passed on to the method.
111 * @return The return value of the method invocation.
112 */
113 decltype(auto) operatorcxx . . $ sigc/mem_functor#`operator()`(6789ee5e487aec83).()(obj_type_with_modifiercxx . . $ sigc/mem_functor#obj_type_with_modifier#& obj, type_trait_take_tcxx . . $ sigc/type_trait_take_t#<T_arg>... a) const
114 {
115 return stdcxx . . $ std/::invokecxx . . $ std/invoke(2acc70346a3bed67).(func_ptr_cxx . . $ sigc/mem_functor#func_ptr_., obj, stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<type_trait_take_tcxx . . $ sigc/type_trait_take_t#<T_arg>>(a)...);
116 }
117
118 protected:
119 function_typecxx . . $ sigc/mem_functor#function_type# func_ptr_cxx . . $ sigc/mem_functor#func_ptr_.;
120 };
121
122 template<typename T_func, typename... T_arg>
123 class bound_mem_functorcxx . . $ sigc/bound_mem_functor# : mem_functorcxx . . $ sigc/mem_functor#<T_func, T_arg...>
124 {
125 using base_typecxx . . $ sigc/bound_mem_functor#base_type# = mem_functorcxx . . $ sigc/mem_functor#<T_func, T_arg...>;
126
127 public:
128 using function_typecxx . . $ sigc/bound_mem_functor#function_type# = typename base_typecxx . . $ sigc/bound_mem_functor#base_type#::function_type;
129
130 using object_typecxx . . $ sigc/bound_mem_functor#object_type# = typename base_typecxx . . $ sigc/bound_mem_functor#base_type#::object_type;
131
132 using obj_type_with_modifiercxx . . $ sigc/bound_mem_functor#obj_type_with_modifier# = typename stdcxx . . $ std/::
133 conditional_t<internalcxx . . $ sigc/internal/::member_method_is_constcxx . . $ sigc/internal/member_method_is_const#<T_func>::value, const object_typecxx . . $ sigc/bound_mem_functor#object_type#, object_typecxx . . $ sigc/bound_mem_functor#object_type#>;
134 using T_limit_referencecxx . . $ sigc/bound_mem_functor#T_limit_reference# =
135 typename stdcxx . . $ std/::conditional_t<internalcxx . . $ sigc/internal/::member_method_is_constcxx . . $ sigc/internal/member_method_is_const#<T_func>::value,
136 limit_referencecxx . . $ sigc/limit_reference#<const object_typecxx . . $ sigc/bound_mem_functor#object_type#>,
137 limit_referencecxx . . $ sigc/limit_reference#<object_typecxx . . $ sigc/bound_mem_functor#object_type#>>;
138
139 /** Constructs a bound_mem_functor object that wraps the passed method.
140 * @param obj Reference to instance the method will operate on.
141 * @param func Pointer to method will be invoked from operator()().
142 */
143 bound_mem_functorcxx . . $ sigc/bound_mem_functor#`bound_mem_functor<T_func, T_arg...>`(ce719af71d77fc3f).(obj_type_with_modifiercxx . . $ sigc/bound_mem_functor#obj_type_with_modifier#& obj, function_typecxx . . $ sigc/bound_mem_functor#function_type# func) : base_typecxx . . $ sigc/bound_mem_functor#base_type#(func), obj_cxx . . $ sigc/bound_mem_functor#obj_.(obj) {}
144
145 /** Execute the wrapped method operating on the stored instance.
146 * @param a Arguments to be passed on to the method.
147 * @return The return value of the method invocation.
148 */
149 decltype(auto) operatorcxx . . $ sigc/bound_mem_functor#`operator()`(5009d1f7d07267e4).()(type_trait_take_tcxx . . $ sigc/type_trait_take_t#<T_arg>... a) const
150 {
151 return stdcxx . . $ std/::invokecxx . . $ std/invoke(2acc70346a3bed67).(
152 this->func_ptr_cxx . . $ sigc/mem_functor#func_ptr_., obj_cxx . . $ sigc/bound_mem_functor#obj_..invoke(), stdcxx . . $ std/::forwardcxx . . $ std/forward(f56228ea88711827).<type_trait_take_tcxx . . $ sigc/type_trait_take_t#<T_arg>>(a)...);
153 }
154
155 // protected:
156 // Reference to stored object instance.
157 // This is the handler object, such as TheObject in void TheObject::signal_handler().
158 T_limit_referencecxx . . $ sigc/bound_mem_functor#T_limit_reference# obj_cxx . . $ sigc/bound_mem_functor#obj_.;
159 };
160
161 #ifndef DOXYGEN_SHOULD_SKIP_THIS
162 // template specialization of visitor<>::do_visit_each<>(action, functor):
163 /** Performs a functor on each of the targets of a functor.
164 * The function overload for sigc::bound_$1mem_functor performs a functor
165 * on the object instance stored in the sigc::bound_$1mem_functor object.
166 *
167 * @ingroup mem_fun
168 */
169 template<typename T_func, typename... T_arg>
170 struct visitorcxx . . $ sigc/visitor#<bound_mem_functorcxx . . $ sigc/bound_mem_functor#<T_func, T_arg...>>
171 {
172 template<typename T_action>
173 static void do_visit_eachcxx . . $ sigc/visitor#do_visit_each(e7f8806c81fa2c2b).(const T_action& action,
174 const bound_mem_functorcxx . . $ sigc/bound_mem_functor#<T_func, T_arg...>& target)
175 {
176 sigccxx . . $ sigc/::visit_eachcxx . . $ sigc/visit_each(13c11f7bd0e7e3d2).(action, target.obj_cxx . . $ sigc/bound_mem_functor#obj_.);
177 }
178 };
179 #endif // DOXYGEN_SHOULD_SKIP_THIS
180
181 /** Creates a functor of type sigc::mem_functor which wraps a method.
182 * @param func Pointer to method that should be wrapped.
183 * @return Functor that executes func on invocation.
184 *
185 * @ingroup mem_fun
186 */
187 template<typename T_return, typename T_obj, typename... T_arg>
188 inline decltype(auto) mem_funcxx . . $ sigc/mem_fun(f59e69f74fd4b604).(T_return (T_obj::*func)(T_arg...))
189 {
190 return mem_functorcxx . . $ sigc/mem_functor#<T_return (T_obj::*)(T_arg...), T_arg...>(func);
191 }
192
193 /** Creates a functor of type sigc::const_mem_functor which wraps a const method.
194 * @param func Pointer to method that should be wrapped.
195 * @return Functor that executes func on invocation.
196 *
197 * @ingroup mem_fun
198 */
199 template<typename T_return, typename T_obj, typename... T_arg>
200 inline decltype(auto)
201 mem_funcxx . . $ sigc/mem_fun(a0892b5e80d53d96).(T_return (T_obj::*func)(T_arg...) const)
202 {
203 return mem_functorcxx . . $ sigc/mem_functor#<T_return (T_obj::*)(T_arg...) const, T_arg...>(func);
204 }
205
206 /** Creates a functor of type sigc::volatile_mem_functor which wraps a volatile method.
207 * @param func Pointer to method that should be wrapped.
208 * @return Functor that executes func on invocation.
209 *
210 * @ingroup mem_fun
211 */
212 template<typename T_return, typename T_obj, typename... T_arg>
213 inline decltype(auto) mem_funcxx . . $ sigc/mem_fun(5be22502a6b61a70).(T_return (T_obj::*func)(T_arg...) volatile)
214 {
215 return mem_functorcxx . . $ sigc/mem_functor#<T_return (T_obj::*)(T_arg...) volatile, T_arg...>(func);
216 }
217
218 /** Creates a functor of type sigc::const_volatile_mem_functor which wraps a const volatile method.
219 * @param func Pointer to method that should be wrapped.
220 * @return Functor that executes func on invocation.
221 *
222 * @ingroup mem_fun
223 */
224 template<typename T_return, typename T_obj, typename... T_arg>
225 inline decltype(auto)
226 mem_funcxx . . $ sigc/mem_fun(6e10fb9f84fdf87f).(T_return (T_obj::*func)(T_arg...) const volatile)
227 {
228 return mem_functorcxx . . $ sigc/mem_functor#<T_return (T_obj::*)(T_arg...) const volatile, T_arg...>(func);
229 }
230
231 /** Creates a functor of type sigc::bound_mem_functor which encapsulates a method and an object
232 * instance.
233 * @param obj Reference to object instance the functor should operate on.
234 * @param func Pointer to method that should be wrapped.
235 * @return Functor that executes @e func on invocation.
236 *
237 * @ingroup mem_fun
238 */
239 template<typename T_return, typename T_obj, typename T_obj2, typename... T_arg>
240 inline decltype(auto)
241 mem_funcxx . . $ sigc/mem_fun(29f9a1a1a7f6cf05).(/**/ T_obj& obj, T_return (T_obj2::*func)(T_arg...))
242 {
243 return bound_mem_functorcxx . . $ sigc/bound_mem_functor#<T_return (T_obj::*)(T_arg...), T_arg...>(obj, func);
244 }
245
246 /** Creates a functor of type sigc::bound_const_mem_functor which encapsulates a method and an
247 * object instance.
248 * @param obj Reference to object instance the functor should operate on.
249 * @param func Pointer to method that should be wrapped.
250 * @return Functor that executes @e func on invocation.
251 *
252 * @ingroup mem_fun
253 */
254 template<typename T_return, typename T_obj, typename T_obj2, typename... T_arg>
255 inline decltype(auto)
256 mem_funcxx . . $ sigc/mem_fun(ad9eeead37f566af).(/*const*/ T_obj& obj, T_return (T_obj2::*func)(T_arg...) const)
257 {
258 return bound_mem_functorcxx . . $ sigc/bound_mem_functor#<T_return (T_obj::*)(T_arg...) const, T_arg...>(obj, func);
259 }
260
261 /** Creates a functor of type sigc::bound_volatile_mem_functor which encapsulates a method and an
262 * object instance.
263 * @param obj Reference to object instance the functor should operate on.
264 * @param func Pointer to method that should be wrapped.
265 * @return Functor that executes @e func on invocation.
266 *
267 * @ingroup mem_fun
268 */
269 template<typename T_return, typename T_obj, typename T_obj2, typename... T_arg>
270 inline decltype(auto)
271 mem_funcxx . . $ sigc/mem_fun(f041c0209ec7da0c).(/**/ T_obj& obj, T_return (T_obj2::*func)(T_arg...) volatile)
272 {
273 return bound_mem_functorcxx . . $ sigc/bound_mem_functor#<T_return (T_obj::*)(T_arg...) volatile, T_arg...>(obj, func);
274 }
275
276 /** Creates a functor of type sigc::bound_const_volatile_mem_functor which encapsulates a method and
277 * an object instance.
278 * @param obj Reference to object instance the functor should operate on.
279 * @param func Pointer to method that should be wrapped.
280 * @return Functor that executes @e func on invocation.
281 *
282 * @ingroup mem_fun
283 */
284 template<typename T_return, typename T_obj, typename T_obj2, typename... T_arg>
285 inline decltype(auto)
286 mem_funcxx . . $ sigc/mem_fun(87a1194e6115593e).(/*const*/ T_obj& obj, T_return (T_obj2::*func)(T_arg...) const volatile)
287 {
288 return bound_mem_functorcxx . . $ sigc/bound_mem_functor#<T_return (T_obj::*)(T_arg...) const volatile, T_arg...>(obj, func);
289 }
290
291 } /* namespace sigc */
292 #endif /* SIGC_FUNCTORS_MEM_FUN_H */