2 /* Do not edit! -- generated file */
3 #ifndef _SIGC_ADAPTORS_ADAPTOR_TRAIT_H_
4 #define _SIGC_ADAPTORS_ADAPTOR_TRAIT_H_
5 #include <sigc++config.h> //To get SIGC_TEMPLATE_KEYWORD_OPERATOR_OVERLOAD
6 #include <sigc++/visit_each.h>
7 #include <sigc++/functors/functor_trait.h>
8 #include <sigc++/functors/ptr_fun.h>
9 #include <sigc++/functors/mem_fun.h>
10 #include <sigc++/adaptors/deduce_result_type.h>
14 // Call either operator()<>() or sun_forte_workaround<>(),
15 // depending on the compiler:
16 #ifdef SIGC_GCC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
17 #define SIGC_WORKAROUND_OPERATOR_PARENTHESES template operator()
18 #define SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
20 #ifdef SIGC_MSVC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
21 #define SIGC_WORKAROUND_OPERATOR_PARENTHESES operator()
22 #define SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
24 #define SIGC_WORKAROUND_OPERATOR_PARENTHESES sun_forte_workaround
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 template <class T_functor> struct adapts;
33 /** @defgroup adaptors Adaptors
34 * Adaptors are functors that alter the signature of a functor's
37 * The adaptor types libsigc++ provides
38 * are created with bind(), bind_return(), hide(), hide_return(),
39 * retype_return(), retype(), compose(), exception_catch(), track_obj()
42 * You can easily derive your own adaptor type from sigc::adapts.
45 /** Converts an arbitrary functor into an adaptor type.
46 * All adaptor types in libsigc++ have
47 * a <tt>template operator()</tt> member of every argument count
48 * they support. These functions in turn invoke a stored adaptor's
49 * <tt>template operator()</tt>, processing the arguments and return
50 * value in a characteristic manner. Explicit function template
51 * instantiation is used to pass type hints thus saving copy costs.
53 * adaptor_functor is a glue between adaptors and arbitrary functors
54 * that just passes on the arguments. You won't use this type directly.
56 * The template argument @e T_functor determines the type of stored
61 template <class T_functor>
62 struct adaptor_functor : public adaptor_base
64 #ifndef DOXYGEN_SHOULD_SKIP_THIS
65 template <class T_arg1=void, class T_arg2=void, class T_arg3=void, class T_arg4=void, class T_arg5=void, class T_arg6=void, class T_arg7=void>
66 struct deduce_result_type
67 { typedef sigc::deduce_result_t<T_functor, T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7> type; };
69 typedef typename functor_trait<T_functor>::result_type result_type;
71 /** Invokes the wrapped functor passing on the arguments.
72 * @return The return value of the functor invocation.
77 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
78 result_type sun_forte_workaround() const
79 { return operator(); }
82 /** Invokes the wrapped functor passing on the arguments.
83 * @param _A_arg1 Argument to be passed on to the functor.
84 * @return The return value of the functor invocation.
86 template <class T_arg1>
87 typename deduce_result_type<T_arg1>::type
88 operator()(T_arg1 _A_arg1) const
89 { return functor_(_A_arg1); }
91 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
92 template <class T_arg1>
93 typename deduce_result_type<T_arg1>::type
94 sun_forte_workaround(T_arg1 _A_arg1) const
95 { //Just calling operator() tries to copy the argument:
96 return functor_(_A_arg1);
100 /** Invokes the wrapped functor passing on the arguments.
101 * @param _A_arg1 Argument to be passed on to the functor.
102 * @param _A_arg2 Argument to be passed on to the functor.
103 * @return The return value of the functor invocation.
105 template <class T_arg1, class T_arg2>
106 typename deduce_result_type<T_arg1, T_arg2>::type
107 operator()(T_arg1 _A_arg1, T_arg2 _A_arg2) const
108 { return functor_(_A_arg1, _A_arg2); }
110 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
111 template <class T_arg1, class T_arg2>
112 typename deduce_result_type<T_arg1, T_arg2>::type
113 sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2) const
114 { //Just calling operator() tries to copy the argument:
115 return functor_(_A_arg1, _A_arg2);
119 /** Invokes the wrapped functor passing on the arguments.
120 * @param _A_arg1 Argument to be passed on to the functor.
121 * @param _A_arg2 Argument to be passed on to the functor.
122 * @param _A_arg3 Argument to be passed on to the functor.
123 * @return The return value of the functor invocation.
125 template <class T_arg1, class T_arg2, class T_arg3>
126 typename deduce_result_type<T_arg1, T_arg2, T_arg3>::type
127 operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3) const
128 { return functor_(_A_arg1, _A_arg2, _A_arg3); }
130 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
131 template <class T_arg1, class T_arg2, class T_arg3>
132 typename deduce_result_type<T_arg1, T_arg2, T_arg3>::type
133 sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3) const
134 { //Just calling operator() tries to copy the argument:
135 return functor_(_A_arg1, _A_arg2, _A_arg3);
139 /** Invokes the wrapped functor passing on the arguments.
140 * @param _A_arg1 Argument to be passed on to the functor.
141 * @param _A_arg2 Argument to be passed on to the functor.
142 * @param _A_arg3 Argument to be passed on to the functor.
143 * @param _A_arg4 Argument to be passed on to the functor.
144 * @return The return value of the functor invocation.
146 template <class T_arg1, class T_arg2, class T_arg3, class T_arg4>
147 typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4>::type
148 operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4) const
149 { return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4); }
151 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
152 template <class T_arg1, class T_arg2, class T_arg3, class T_arg4>
153 typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4>::type
154 sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4) const
155 { //Just calling operator() tries to copy the argument:
156 return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4);
160 /** Invokes the wrapped functor passing on the arguments.
161 * @param _A_arg1 Argument to be passed on to the functor.
162 * @param _A_arg2 Argument to be passed on to the functor.
163 * @param _A_arg3 Argument to be passed on to the functor.
164 * @param _A_arg4 Argument to be passed on to the functor.
165 * @param _A_arg5 Argument to be passed on to the functor.
166 * @return The return value of the functor invocation.
168 template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5>
169 typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5>::type
170 operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5) const
171 { return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5); }
173 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
174 template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5>
175 typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5>::type
176 sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5) const
177 { //Just calling operator() tries to copy the argument:
178 return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5);
182 /** Invokes the wrapped functor passing on the arguments.
183 * @param _A_arg1 Argument to be passed on to the functor.
184 * @param _A_arg2 Argument to be passed on to the functor.
185 * @param _A_arg3 Argument to be passed on to the functor.
186 * @param _A_arg4 Argument to be passed on to the functor.
187 * @param _A_arg5 Argument to be passed on to the functor.
188 * @param _A_arg6 Argument to be passed on to the functor.
189 * @return The return value of the functor invocation.
191 template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6>
192 typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6>::type
193 operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5, T_arg6 _A_arg6) const
194 { return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5, _A_arg6); }
196 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
197 template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6>
198 typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6>::type
199 sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5, T_arg6 _A_arg6) const
200 { //Just calling operator() tries to copy the argument:
201 return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5, _A_arg6);
205 /** Invokes the wrapped functor passing on the arguments.
206 * @param _A_arg1 Argument to be passed on to the functor.
207 * @param _A_arg2 Argument to be passed on to the functor.
208 * @param _A_arg3 Argument to be passed on to the functor.
209 * @param _A_arg4 Argument to be passed on to the functor.
210 * @param _A_arg5 Argument to be passed on to the functor.
211 * @param _A_arg6 Argument to be passed on to the functor.
212 * @param _A_arg7 Argument to be passed on to the functor.
213 * @return The return value of the functor invocation.
215 template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6, class T_arg7>
216 typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7>::type
217 operator()(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5, T_arg6 _A_arg6, T_arg7 _A_arg7) const
218 { return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5, _A_arg6, _A_arg7); }
220 #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
221 template <class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6, class T_arg7>
222 typename deduce_result_type<T_arg1, T_arg2, T_arg3, T_arg4, T_arg5, T_arg6, T_arg7>::type
223 sun_forte_workaround(T_arg1 _A_arg1, T_arg2 _A_arg2, T_arg3 _A_arg3, T_arg4 _A_arg4, T_arg5 _A_arg5, T_arg6 _A_arg6, T_arg7 _A_arg7) const
224 { //Just calling operator() tries to copy the argument:
225 return functor_(_A_arg1, _A_arg2, _A_arg3, _A_arg4, _A_arg5, _A_arg6, _A_arg7);
229 /// Constructs an invalid functor.
233 /** Constructs an adaptor_functor object that wraps the passed functor.
234 * @param _A_functor Functor to invoke from operator()().
236 explicit adaptor_functor(const T_functor& _A_functor)
237 : functor_(_A_functor)
240 /** Constructs an adaptor_functor object that wraps the passed (member)
242 * @param _A_type Pointer to function or class method to invoke from operator()().
244 template <class T_type>
245 explicit adaptor_functor(const T_type& _A_type)
249 /// Functor that is invoked from operator()().
250 mutable T_functor functor_;
253 template <class T_functor>
254 typename adaptor_functor<T_functor>::result_type
255 adaptor_functor<T_functor>::operator()() const
256 { return functor_(); }
258 #ifndef DOXYGEN_SHOULD_SKIP_THIS
259 //template specialization of visitor<>::do_visit_each<>(action, functor):
260 /** Performs a functor on each of the targets of a functor.
261 * The function overload for sigc::adaptor_functor performs a functor
262 * on the functor stored in the sigc::adaptor_functor object.
266 template <class T_functor>
267 struct visitor<adaptor_functor<T_functor> >
269 template <class T_action>
270 static void do_visit_each(const T_action& _A_action,
271 const adaptor_functor<T_functor>& _A_target)
273 sigc::visit_each(_A_action, _A_target.functor_);
276 #endif // DOXYGEN_SHOULD_SKIP_THIS
278 /** Trait that specifies what is the adaptor version of a functor type.
279 * Template specializations for sigc::adaptor_base derived functors,
280 * for function pointers and for class methods are provided.
282 * The template argument @e T_functor is the functor type to convert.
283 * @e I_isadaptor indicates whether @e T_functor inherits from sigc::adaptor_base.
287 #ifndef DOXYGEN_SHOULD_SKIP_THIS
288 template <class T_functor, bool I_isadaptor = std::is_base_of<adaptor_base, T_functor>::value> struct adaptor_trait;
290 template <class T_functor, bool I_isadaptor = std::is_base_of<adaptor_base, T_functor>::value> struct adaptor_trait {};
293 /** Trait that specifies what is the adaptor version of a functor type.
294 * This template specialization is used for types that inherit from adaptor_base.
295 * adaptor_type is equal to @p T_functor in this case.
297 template <class T_functor>
298 struct adaptor_trait<T_functor, true>
300 typedef typename T_functor::result_type result_type;
301 typedef T_functor functor_type;
302 typedef T_functor adaptor_type;
305 /** Trait that specifies what is the adaptor version of a functor type.
306 * This template specialization is used for arbitrary functors,
307 * for function pointers and for class methods are provided.
308 * The latter are converted into @p pointer_functor or @p mem_functor types.
309 * adaptor_type is equal to @p adaptor_functor<functor_type>.
311 template <class T_functor>
312 struct adaptor_trait<T_functor, false>
314 typedef typename functor_trait<T_functor>::result_type result_type;
315 typedef typename functor_trait<T_functor>::functor_type functor_type;
316 typedef adaptor_functor<functor_type> adaptor_type;
319 // Doxygen (at least version 1.8.4) removes blank lines in a code block.
320 // That's why there are empty comment lines in the following code block.
321 /** Base type for adaptors.
322 * sigc::adapts wraps adaptors, functors, function pointers and class methods.
323 * It contains a single member functor which is always a sigc::adaptor_base.
324 * The typedef adaptor_type defines the exact type that is used
325 * to store the adaptor, functor, function pointer or class method passed
326 * into the constructor. It differs from @a T_functor unless @a T_functor
327 * inherits from sigc::adaptor_base.
329 * @par Example of a simple adaptor:
333 * template <class T_functor>
334 * struct my_adaptor : public sigc::adapts<T_functor>
336 * template <class T_arg1=void, class T_arg2=void>
337 * struct deduce_result_type
338 * { typedef sigc::deduce_result_t<T_functor, T_arg1, T_arg2> type; };
339 * typedef typename sigc::functor_trait<T_functor>::result_type result_type;
342 * operator()() const;
344 * template <class T_arg1>
345 * typename deduce_result_type<T_arg1>::type
346 * operator()(T_arg1 _A_arg1) const;
348 * template <class T_arg1, class T_arg2>
349 * typename deduce_result_type<T_arg1, T_arg2>::type
350 * operator()(T_arg1 _A_arg1, T_arg2 _A_arg2) const;
352 * // Constructs a my_adaptor object that wraps the passed functor.
353 * // Initializes adapts<T_functor>::functor_, which is invoked from operator()().
354 * explicit my_adaptor(const T_functor& _A_functor)
355 * : sigc::adapts<T_functor>(_A_functor) {}
357 * } // end namespace my_ns
359 * // Specialization of sigc::visitor for my_adaptor.
362 * template <class T_functor>
363 * struct visitor<my_ns::my_adaptor<T_functor> >
365 * template <class T_action>
366 * static void do_visit_each(const T_action& _A_action,
367 * const my_ns::my_adaptor<T_functor>& _A_target)
369 * sigc::visit_each(_A_action, _A_target.functor_);
372 * } // end namespace sigc
375 * If you implement your own adaptor, you must also provide your specialization
376 * of sigc::visitor<>::do_visit_each<>() that will forward the call to the functor(s)
377 * your adapter is wrapping. Otherwise, pointers stored within the functor won't be
378 * invalidated when a sigc::trackable object is destroyed and you can end up
379 * executing callbacks on destroyed objects.
381 * Your specialization of sigc::visitor<> must be in namespace sigc.
385 template <class T_functor>
386 struct adapts : public adaptor_base
388 typedef typename adaptor_trait<T_functor>::result_type result_type;
389 typedef typename adaptor_trait<T_functor>::adaptor_type adaptor_type;
391 /** Constructs an adaptor that wraps the passed functor.
392 * @param _A_functor Functor to invoke from operator()().
394 explicit adapts(const T_functor& _A_functor)
395 : functor_(_A_functor)
398 /// Adaptor that is invoked from operator()().
399 mutable adaptor_type functor_;
402 } /* namespace sigc */
403 #endif /* _SIGC_ADAPTORS_ADAPTOR_TRAIT_H_ */