Skip to content

Commit 1d5c908

Browse files
author
Kjell Ahlstedt
committed
Improve the documentation of mem_fun()
* sigc++/functors/macros/mem_fun.h.m4: * sigc++/functors/slot_base.h: Make it clear that mem_fun() does not return a slot, and 'auto s = sigc::mem_fun(....)' is not equivalent to 'sigc::slot<....> s = sigc::mem_fun(....)'. The confusing documentation was noted by Andrejs Hanins on libsigc-list.
1 parent 9526ba2 commit 1d5c908

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

sigc++/functors/macros/mem_fun.h.m4

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ namespace sigc {
199199
* mem_fun() is used to convert a pointer to a method to a functor.
200200
*
201201
* Optionally, a reference or pointer to an object can be bound to the functor.
202-
* Note that only if the object type inherits from sigc::trackable is
203-
* the slot automatically cleared when the object goes out of scope!
202+
*
203+
* @note Only if the object type inherits from sigc::trackable, and the
204+
* functor returned from mem_fun() is assigned to a sigc::slot, is the functor
205+
* automatically cleared when the object goes out of scope!
204206
*
205207
* If the member function pointer is to an overloaded type, you must specify
206208
* the types using template arguments starting with the first argument.
@@ -214,6 +216,8 @@ namespace sigc {
214216
* };
215217
* foo my_foo;
216218
* sigc::slot<void, int> sl = sigc::mem_fun(my_foo, &foo::bar);
219+
* // Note: f is not a slot. It will not be invalidated when my_foo is deleted.
220+
* auto f = sigc::mem_fun(my_foo, &foo::bar); // Usually not what you want.
217221
* @endcode
218222
*
219223
* For const methods mem_fun() takes a const reference or pointer to an object.

sigc++/functors/slot_base.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,18 @@ struct SIGC_API slot_do_unbind
179179

180180
/** @defgroup slot Slots
181181
* Slots are type-safe representations of callback methods and functions.
182-
* A Slot can be constructed from any function object or function, regardless of
182+
* A slot can be constructed from any function object or function, regardless of
183183
* whether it is a global function, a member method, static, or virtual.
184184
*
185185
* Use the sigc::mem_fun() and sigc::ptr_fun() template functions to get a sigc::slot, like so:
186-
*
187186
* @code
188187
* sigc::slot<void, int> sl = sigc::mem_fun(someobj, &SomeClass::somemethod);
189188
* @endcode
190-
*
191189
* or
192-
*
193190
* @code
194191
* sigc::slot<void, int> sl = sigc::ptr_fun(&somefunction);
195192
* @endcode
196-
*
197-
* or
198-
*
193+
* or, in gtkmm,
199194
* @code
200195
* m_Button.signal_clicked().connect( sigc::mem_fun(*this, &MyWindow::on_button_clicked) );
201196
* @endcode
@@ -204,6 +199,16 @@ struct SIGC_API slot_do_unbind
204199
*
205200
* You can also pass slots as method parameters where you might normally pass a function pointer.
206201
*
202+
* sigc::mem_fun() and sigc::ptr_fun() return functors, but those functors are
203+
* not slots.
204+
* @code
205+
* sigc::slot<void, int> sl = sigc::mem_fun(someobj, &SomeClass::somemethod);
206+
* @endcode
207+
* is not equivalent to
208+
* @code
209+
* auto sl = sigc::mem_fun(someobj, &SomeClass::somemethod); // Not a slot!
210+
* @endcode
211+
*
207212
* A C++11 lambda expression is a functor (function object). It is automatically
208213
* wrapped in a slot, if it is connected to a signal.
209214
* @code

0 commit comments

Comments
 (0)