Topic: Notification function for shared_from_this


Author: =?UTF-8?Q?Micha=C5=82_Dominiak?= <griwes@griwes.info>
Date: Mon, 16 May 2016 16:38:34 +0000
Raw View
--001a113eb08efc7f1b0532f8415b
Content-Type: text/plain; charset=UTF-8

Hi,

I like this due to a thing I'm currently working on, because otherwise I
have to check for the type information later on to see if I should do a
thing with the shared pointer or not, which would be easier this way, but I
can see why some people could be directly opposed to this feature (for
possibly directly making shared pointers even more abused than they are
currently).

On Mon, May 16, 2016 at 5:56 PM 'Johannes Schaub' via ISO C++ Standard -
Future Proposals <std-proposals@isocpp.org> wrote:

> The need of "virtual" can be mitigated by using the fact that
> enable_shared_from_this is actually a CRTP base. So it suffices if it
> called static_cast<T*>(ptr)->attached(), and T may decide on its own
> whether it wants it virtual or not.
>
> 2016-05-16 17:51 GMT+02:00 Johannes Schaub <schaub.johannes@googlemail.com
> >:
> > I was thinking about constructors of classes that derive from
> > enable_shared_from_this. A problem with these classes is that the
> > shared_from_this() function is not available from the constructor,
> > because only afterwards, the object will be owned by a shared_ptr
> >
> >     class F : public enable_shared_from_this {
> >     public:
> >         F() {
> >            doSomething(shared_from_this());
> >         }
> >     }
> >
> >     int main() { std::make_shared<F>(); }
> >
> > The code is broken. However, if shared_ptr called a function after it
> > attached to F, this can be written
> >
> >     class F : public enable_shared_from_this {
> >     private:
> >         virtual void attached() {
> >            doSomething(shared_from_this());
> >         }
> >     }
> >
> >     int main() { std::make_shared<F>(); }
> >
> > What are your thoughts on this?
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANu6V4WjPSTTtOSj%3D0ML%3DNpaU9dWEpLT2SoY%2BOSq5qOH7MA2BA%40mail.gmail.com
> .
>

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAPCFJdS1xkjJemXYqp8g_qY33XXKhrQW3LT%2B0KEotfvJOu-LYw%40mail.gmail.com.

--001a113eb08efc7f1b0532f8415b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,</div><div><br></div>I like this due to a thing I&=
#39;m currently working on, because otherwise I have to check for the type =
information later on to see if I should do a thing with the shared pointer =
or not, which would be easier this way, but I can see why some people could=
 be directly opposed to this feature (for possibly directly making shared p=
ointers even more abused than they are currently).</div><br><div class=3D"g=
mail_quote"><div dir=3D"ltr">On Mon, May 16, 2016 at 5:56 PM &#39;Johannes =
Schaub&#39; via ISO C++ Standard - Future Proposals &lt;<a href=3D"mailto:s=
td-proposals@isocpp.org">std-proposals@isocpp.org</a>&gt; wrote:<br></div><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
 #ccc solid;padding-left:1ex">The need of &quot;virtual&quot; can be mitiga=
ted by using the fact that<br>
enable_shared_from_this is actually a CRTP base. So it suffices if it<br>
called static_cast&lt;T*&gt;(ptr)-&gt;attached(), and T may decide on its o=
wn<br>
whether it wants it virtual or not.<br>
<br>
2016-05-16 17:51 GMT+02:00 Johannes Schaub &lt;<a href=3D"mailto:schaub.joh=
annes@googlemail.com" target=3D"_blank">schaub.johannes@googlemail.com</a>&=
gt;:<br>
&gt; I was thinking about constructors of classes that derive from<br>
&gt; enable_shared_from_this. A problem with these classes is that the<br>
&gt; shared_from_this() function is not available from the constructor,<br>
&gt; because only afterwards, the object will be owned by a shared_ptr<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0class F : public enable_shared_from_this {<br>
&gt;=C2=A0 =C2=A0 =C2=A0public:<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0F() {<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 doSomething(shared_from_this(=
));<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
&gt;=C2=A0 =C2=A0 =C2=A0}<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0int main() { std::make_shared&lt;F&gt;(); }<br>
&gt;<br>
&gt; The code is broken. However, if shared_ptr called a function after it<=
br>
&gt; attached to F, this can be written<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0class F : public enable_shared_from_this {<br>
&gt;=C2=A0 =C2=A0 =C2=A0private:<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0virtual void attached() {<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 doSomething(shared_from_this(=
));<br>
&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}<br>
&gt;=C2=A0 =C2=A0 =C2=A0}<br>
&gt;<br>
&gt;=C2=A0 =C2=A0 =C2=A0int main() { std::make_shared&lt;F&gt;(); }<br>
&gt;<br>
&gt; What are your thoughts on this?<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%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CANu6V4WjPSTTtOSj%3D0ML%3DNpaU9dWEpLT=
2SoY%2BOSq5qOH7MA2BA%40mail.gmail.com" rel=3D"noreferrer" target=3D"_blank"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANu6V4WjPSTT=
tOSj%3D0ML%3DNpaU9dWEpLT2SoY%2BOSq5qOH7MA2BA%40mail.gmail.com</a>.<br>
</blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAPCFJdS1xkjJemXYqp8g_qY33XXKhrQW3LT%=
2B0KEotfvJOu-LYw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAPCFJdS1xkjJem=
XYqp8g_qY33XXKhrQW3LT%2B0KEotfvJOu-LYw%40mail.gmail.com</a>.<br />

--001a113eb08efc7f1b0532f8415b--

.


Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Mon, 23 May 2016 18:06:37 +0200
Raw View
On 05/23/2016 05:22 PM, Jakob Riedle wrote:

> How do you do atomic instructions?

#include <atomic>

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/57432A8D.3090103%40mail1.stofanet.dk.

.