220 17896 <bff2235f-a217-47b8-8441-f3f8da87f712@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: smart function pointer proposal
Date: Fri, 15 May 2015 11:41:18 -0700 (PDT)
Lines: 156
Approved: news@gmane.org
Message-ID: <bff2235f-a217-47b8-8441-f3f8da87f712@isocpp.org>
References: <736df6af-cd5e-4625-a4bb-be3cfd49a67e@isocpp.org>
 <2A6D8713-02D7-420A-A3D9-17F7C1D2C7F6@mac.com>
 <ea757332-82ef-4043-b63e-a9159a0bb0e3@isocpp.org>
 <662b2b76-f8b2-4189-8eac-4b1d3a64e319@isocpp.org>
 <04e8b03f-5f43-41b2-8039-19ca11d31dfc@isocpp.org>
 <aaf36f50-d9fd-4dda-9c08-e359dcaba19e@isocpp.org>
 <CADvuK0Lo-7tvXmawXficO7nocTt9bPMT0OD4qCTQMtkZGEFR0A@mail.gmail.com>
 <8a1bb50e-aa86-4f29-9906-c279b2413914@isocpp.org>
 <2789e87a-9b41-4f95-ab17-9fe15d015a0f@isocpp.org>
 <502f2509-6aef-4776-8b40-ce6c8cb72c24@isocpp.org>
 <7e9a7010-cc2c-432f-980d-dc17e7d478fa@isocpp.org>
 <0ada2ccf-38af-4b9d-b8af-4029048bb478@isocpp.org>
 <6b4119ff-e944-48eb-b391-2669dae63bea@isocpp.org>
 <58faea9e-b2af-460d-80e5-3da2deee7cfb@isocpp.org>
 <015c0f79-6051-4864-9fc4-acac543ec5bc@isocpp.org>
 <ea01f02f-db08-410b-abc5-608e2435584d@isocpp.org>
 <8d7e946a-32f0-4e30-a35c-24f873373cab@isocpp.org>
 <371b996d-48a1-4007-a8a7-0bcaa047fd00@isocpp.org>
 <fa321754-b218-4cea-9a0f-3a7c5a3ee754@isocpp.org>
 <01129576-7ef2-4ac3-b7b7-3ea38e33e127@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1041_539864701.1431715278235"
X-Trace: ger.gmane.org 1431715284 24293 80.91.229.3 (15 May 2015 18:41:24 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 15 May 2015 18:41:24 +0000 (UTC)
Cc: mash.boyko2014@gmail.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBTX33CVAKGQESJPZXTI@isocpp.org Fri May 15 20:41:22 2015
Return-path: <std-proposals+bncBCEKFTV6ZUMBBTX33CVAKGQESJPZXTI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f198.google.com ([209.85.216.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBTX33CVAKGQESJPZXTI@isocpp.org>)
	id 1YtKXw-0005yR-IQ
	for gclcip-std-proposals@m.gmane.org; Fri, 15 May 2015 20:41:20 +0200
Original-Received: by qcbmu5 with SMTP id mu5sf96425511qcb.0
        for <gclcip-std-proposals@m.gmane.org>; Fri, 15 May 2015 11:41:19 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:content-type:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=4fkYNm8G7w6k5gyYJ3gHK6f9VICJpdLVjfVZBsc60VM=;
        b=IRSICtG1YS9BbsUp7AQOD+hLK6zPmRJfYBdU1CxTmSw4ij1cWFtTq/Q0sAtV+WBrJw
         NSzaa0Kvo4CF7o1frpBQSbZUnolUhfkBxEPuLQzUEx1shyrRxN47L51EyveRQV5NifKG
         aaXtu5cJzHCxJsXwn9+UvqRBLapgWZYucY9w6tkqxTn883NFnilJN8d5zDzgASp2xEGq
         CuCxSxBbFfid6FaYNEWUPKE1l63P35IOyyYU0iZ0KSRfVO+gj7ZGfAU8Ds05fX9PE6xB
         V0fvdbGwzHUZlFxJhw0ZiI+SGtuuhUMrKACqRa26Q+MV9Hx5uHyLARS8Ibj6Cr6Dr8bA
         uLfQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:content-type:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=4fkYNm8G7w6k5gyYJ3gHK6f9VICJpdLVjfVZBsc60VM=;
        b=ge4TB7AcfNPfqhYWTx115b6KXmDHa0cycZeB1XcxS2JZzn3nbnKZnt/djwYehaz9Ju
         LyD6Zjs9GAIwzeMImO14LO1vZtqUEQIBrq7CpvUIQXGTlVVhULRbjvpioyEwLrCzyzDd
         I+GVGiqzkw81Lfgtb5Fx2EphjACN2pW0bfoU0MSYfwV9ttbvjoqhrEev4vKqTfZKjsJw
         SApcGkhrXm0+jgdI1PyaEMV2oMtAMp0QKW9I62p0+GldYCULLz4MrsrAJHnFaHSeqj3D
         S/rjrSfKRKPx/4IojZ+ZL6S8ptE4AucopFihNcvObObo8wyC1kbeOAHAu3q5IEv0Z5wQ
         eG0Q==
X-Gm-Message-State: ALoCoQmxIdUDInQL7q3dIfRGU1qxVTNjLH+UJ5kFl9XUxUM+Wtn2XyyUX0c+4tbqL0qOBFjFj7RS
X-Received: by 10.236.216.52 with SMTP id f50mr15434570yhp.13.1431715279429;
        Fri, 15 May 2015 11:41:19 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.92.2 with SMTP id a2ls269165qge.46.gmail; Fri, 15 May 2015
 11:41:18 -0700 (PDT)
X-Received: by 10.140.41.40 with SMTP id y37mr190142qgy.1.1431715278809;
        Fri, 15 May 2015 11:41:18 -0700 (PDT)
In-Reply-To: <01129576-7ef2-4ac3-b7b7-3ea38e33e127@isocpp.org>
X-Original-Sender: jmckesson@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:17896
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17896>

------=_Part_1041_539864701.1431715278235
Content-Type: multipart/alternative; 
	boundary="----=_Part_1042_387621132.1431715278235"

------=_Part_1042_387621132.1431715278235
Content-Type: text/plain; charset=UTF-8

On Friday, May 15, 2015 at 2:18:29 PM UTC-4, Michael Boyko wrote:
>
> I didn't say the event was a member of A and I'll disagree with you and 
> say object B has every right to attach A to some event. Its a valid design.
>

Let's say that object B has the right to attach object A to an event. OK, 
fine.

But rights come with *responsibilities*. If you design a system such that 
object B has the right to attach some other object A to events, then object 
B must take on the responsibility to manage that attachment. It needs to 
make sure that A is not destroyed before the connection is broken, for 
example. Because B has done this without A's knowledge, this responsibility 
must rest on B's shoulders, since it got A involved.

There are several ways to handle this. Maybe B stored a shared_ptr<A> in 
the event. Maybe B tells A that it has been connected, so its destructor 
can disconnect it (which also requires that it be able to detect if the 
event E is destroyed). Maybe there's some higher-level construct that is 
informed by B that a connection between A and E has been formed, so it will 
destroy them when A is being destroyed. Or maybe you have an a priori 
assumption that A will always outlive whatever event objects it gets 
attached to.

That last one? I don't see how that is "valid design" in most cases. It's 
certainly not something that should be *encouraged* or made the default 
case. Ignoring one's responsibilities and pretending they don't exist is 
not an effective solution to most problems.

Oh, and here's an interesting way to handle it. Instead of registering a 
member pointer + shared_ptr<A> (assuming your `fun_ptr` can even handle 
that), you instead register a lambda that looks like this:

[ptr = weak_ptr<A>{smart_ptr}](...)
{
  shared_ptr<A> p = ptr.lock();
  if(p) { return p->MemberFunction(...);}
  return {};
}

Oh but that's right; you can't register a lambda with your `fun_ptr` type. 
Too bad; either your event system handles weak relationships manually 
(which is admittedly reasonable... though you wouldn't be able to use your 
`fun_ptr` type to do it), or you're SOL.

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1042_387621132.1431715278235
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Friday, May 15, 2015 at 2:18:29 PM UTC-4, Michael Boyko=
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><=
/div><div>I didn't say the event was a member of A and I'll disagree with y=
ou and say object B&nbsp;has&nbsp;every right to&nbsp;attach A to&nbsp;some=
 event. Its a valid design.</div></div></blockquote><div><br>Let's say that=
 object B has the right to attach object A to an event. OK, fine.<br><br>Bu=
t rights come with <i>responsibilities</i>. If you design a system such tha=
t object B has the right to attach some other object A to events, then obje=
ct B must take on the responsibility to manage that attachment. It needs to=
 make sure that A is not destroyed before the connection is broken, for exa=
mple. Because B has done this without A's knowledge, this responsibility mu=
st rest on B's shoulders, since it got A involved.<br><br>There are several=
 ways to handle this. Maybe B stored a shared_ptr&lt;A&gt; in the event. Ma=
ybe B tells A that it has been connected, so its destructor can disconnect =
it (which also requires that it be able to detect if the event E is destroy=
ed). Maybe there's some higher-level construct that is informed by B that a=
 connection between A and E has been formed, so it will destroy them when A=
 is being destroyed. Or maybe you have an a priori assumption that A will a=
lways outlive whatever event objects it gets attached to.<br><br>That last =
one? I don't see how that is "valid design" in most cases. It's certainly n=
ot something that should be <i>encouraged</i> or made the default case. Ign=
oring one's responsibilities and pretending they don't exist is not an effe=
ctive solution to most problems.<br><br>Oh, and here's an interesting way t=
o handle it. Instead of registering a member pointer + shared_ptr&lt;A&gt; =
(assuming your `fun_ptr` can even handle that), you instead register a lamb=
da that looks like this:<br><br><div class=3D"prettyprint" style=3D"backgro=
und-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-sty=
le: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pretty=
print"><div class=3D"subprettyprint"><span style=3D"color: #660;" class=3D"=
styled-by-prettify">[</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">ptr </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> w=
eak_ptr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">A</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;{</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">smart_ptr</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}](...)</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>&nbsp; shared_ptr</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">A</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> p </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> ptr</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">.</span><span style=3D"color: #008;" class=3D"styled-by-prettify">lock<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">p</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ret=
urn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> p</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;</span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">MemberFunction</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(...);}</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">{};</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">}</span></div></code></div><br>Oh but that's=
 right; you can't register a lambda with your `fun_ptr` type. Too bad; eith=
er your event system handles weak relationships manually (which is admitted=
ly reasonable... though you wouldn't be able to use your `fun_ptr` type to =
do it), or you're SOL.<br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1042_387621132.1431715278235--
------=_Part_1041_539864701.1431715278235--

.
