Re: [sigc] callbacks with std::auto_ptr by value
- From: Ulrich Eckhardt <eckhardt satorlaser com>
- To: libsigc-list gnome org
- Subject: Re: [sigc] callbacks with std::auto_ptr by value
- Date: Mon, 4 Sep 2006 13:45:13 +0200
On Thursday 31 August 2006 22:18, klaus triendl wrote:
> The following code won't compile:
[...]
> void test(std::auto_ptr<int>)
[...]
> int main()
> {
> std::auto_ptr<int> p;
> sigc::ptr_fun(&test)(p);
Yes, and that is good. Point is that sigC++ is a 1:n signalling framework.
Now, imagine that you have two functions called with the same auto_ptr:
std::auto_ptr<int> p;
test1(p);
test2(p);
The result is obviously not going to be what it seems to look like, except to
someone that knows the semantics of auto_ptr and the function signature.
Since sigC++ is a simple signal-routing framework, modification of the signal
(i.e. in this case the auto_ptr) shouldn't take place. If you really want it
to happen, you should explicitly pass a (non-const) reference to an auto_ptr
instead.
This is partially my opinion, but I think this runs analog to the fact that
auto_ptr is simply not copyable - the (abused) copy constructor only
implements move semantics.
> If function arguments are passed by value then sigc internally creates a
> const std::auto_ptr& with the type_trait<std::auto_ptr>::take, but
> std::auto_ptr has a copy constructor that takes a nonconst argument:
> auto_ptr& operator =(auto_ptr& nonconst);
This is exactly the point, but even though it technically is a copy
constructor, it doesn't make auto_ptr copyable, which is a requirement for
passing it to several slots by value.
my 2cc
Uli
**************************************************************************************
Visit our website at <http://www.satorlaser.de/>
**************************************************************************************
Diese E-Mail und jede mit dieser E-Mail versandte Datei ist vertraulich und ausschließlich für die Nutzung durch den vorgesehenen Empfänger bestimmt. Sollten Sie nicht der vorgesehene Empfänger dieser E-Mail sein, informieren Sie bitte den Absender. Jeder unbefugte Zugriff oder unbefugte Weiterleitung, die Fertigung einer Kopie oder sonstige in diesem Zusammenhang stehende Handlung ist untersagt.
This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error, please be so kind to inform the sender. Any other unauthorised access, unauthorised forwarding, copying or other action in this connection at all, is prohibited.
**************************************************************************************
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]