[libsigcplusplus/libsigc++-2-10: 1/2] slot: Allow sigc::slot<R(Args...)> declaration, like std::function.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigcplusplus/libsigc++-2-10: 1/2] slot: Allow sigc::slot<R(Args...)> declaration, like std::function.
- Date: Sat, 12 Mar 2016 15:04:44 +0000 (UTC)
commit 5573e97dd39e0f0c3f2ba6a3d5e56f21895b8796
Author: Murray Cumming <murrayc murrayc com>
Date: Sat Mar 12 15:53:00 2016 +0100
slot: Allow sigc::slot<R(Args...)> declaration, like std::function.
By adding a template specialization that repeats each slot*<>
declarartion, though it would be good to avoid the repetition.
Bug 763393
sigc++/functors/macros/slot.h.m4 | 68 ++++++++++++++++++++++++++++++++++++++
tests/test_slot.cc | 13 +++++++
2 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/sigc++/functors/macros/slot.h.m4 b/sigc++/functors/macros/slot.h.m4
index 5c6436c..891bf3d 100644
--- a/sigc++/functors/macros/slot.h.m4
+++ b/sigc++/functors/macros/slot.h.m4
@@ -254,6 +254,74 @@ public:
}
};
+
+/** Convenience wrapper for the numbered sigc::slot$1 template.
+ * See the base class for useful methods.
+ * This is the template specialization of the unnumbered sigc::slot
+ * template for $1 argument(s), specialized for different numbers of arguments
+ * This is possible because the template has default (nil) template types.
+dnl *
+dnl * @ingroup slot
+ *
+ * This specialization allow use of the sigc::slot<R(Args...)> syntax,
+ */
+template <LIST(class T_return, LOOP(class T_arg%1, $1))>
+class slot<T_return(LIST(LOOP(T_arg%1, $1)))>
+ : public slot$1<LIST(T_return, LOOP(T_arg%1, $1))>
+{
+public:
+ typedef slot$1<LIST(T_return, LOOP(T_arg%1, $1))> parent_type;
+
+ inline slot() {}
+
+ /** Constructs a slot from an arbitrary functor.
+ * @param _A_func The desired functor the new slot should be assigned to.
+ */
+ template <class T_functor>
+ slot(const T_functor& _A_func)
+ : parent_type(_A_func) {}
+
+ // Without static_cast parent_type(const T_functor& _A_func)
+ // is called instead of the copy constructor.
+ /** Constructs a slot, copying an existing one.
+ * @param src The existing slot to copy.
+ */
+ slot(const slot& src)
+ : parent_type(static_cast<const parent_type&>(src)) {}
+
+ // Without static_cast parent_type(const T_functor& _A_func)
+ // is called instead of the move constructor.
+ /** Constructs a slot, moving an existing one.
+ * If @p src is connected to a parent (e.g. a signal), it is copied, not moved.
+ * @param src The existing slot to move or copy.
+ */
+ slot(slot&& src)
+ : parent_type(std::move(static_cast<parent_type&>(src))) {}
+
+ /** Overrides this slot, making a copy from another slot.
+ * @param src The slot from which to make a copy.
+ * @return @p this.
+ */
+ slot& operator=(const slot& src)
+ {
+ parent_type::operator=(src);
+ return *this;
+ }
+
+ /** Overrides this slot, making a move from another slot.
+ * If @p src is connected to a parent (e.g. a signal), it is copied, not moved.
+ * @param src The slot from which to move or copy.
+ * @return @p this.
+ */
+ slot& operator=(slot&& src)
+ {
+ parent_type::operator=(std::move(src));
+ return *this;
+ }
+};
+
+
+
ifelse($1, $2,[dnl
#ifndef DOXYGEN_SHOULD_SKIP_THIS
//template specialization of visitor<>::do_visit_each<>(action, functor):
diff --git a/tests/test_slot.cc b/tests/test_slot.cc
index 49c0226..40e55dc 100644
--- a/tests/test_slot.cc
+++ b/tests/test_slot.cc
@@ -50,6 +50,18 @@ void test_simple()
util->check_result(result_stream, "foo(int 2)");
}
+void test_std_function_style_syntax()
+{
+ // simple test
+ sigc::slot<void(int)> s1 = foo();
+ s1(1);
+ util->check_result(result_stream, "foo(int 1)");
+
+ s1 = foo();
+ s1(2);
+ util->check_result(result_stream, "foo(int 2)");
+}
+
void test_implicit_conversion()
{
// test implicit conversion
@@ -100,6 +112,7 @@ int main(int argc, char* argv[])
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
test_simple();
+ test_std_function_style_syntax();
test_implicit_conversion();
test_reference();
test_operator_equals();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]