Topic: Proposal for standard library: std::reset
Author: "'Walt Karas' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Sun, 25 Jun 2017 11:24:31 -0700 (PDT)
Raw View
------=_Part_1522_421985346.1498415071377
Content-Type: multipart/alternative;
boundary="----=_Part_1523_705212607.1498415071377"
------=_Part_1523_705212607.1498415071377
Content-Type: text/plain; charset="UTF-8"
The reference implementation would be:
template <typename T> reset(T &v) { T tmp{static_cast<T &&>(v)}; }
It releases any dynamically-allocated resources held by an object, leaving
it in a safe state to be assigned or destroyed.
Motivation: I want to communicate a value set in one thread and used in
another. I'm thinking to write a class template, with 2 variables to hold
the value, and to use ping-pong buffering, to ease the atomicity issues of
the setting thread creating a new value for the using thread. I want to
reset the old value when the using thread switches to the new value. The
reset will safely release any dynamically-allocated resources used by the
old value, but be optimized out for values of simpler types that don't have
dynamically allocated resources.
--
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/073535d5-6be5-4385-846d-e52291d38a1b%40isocpp.org.
------=_Part_1523_705212607.1498415071377
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">The reference implementation would be:<div><br></div><div>=
template <typename T> reset(T &v) { T tmp{static_cast<T &&=
amp;>(v)}; }<br></div><div><br></div><div>It releases any dynamically-al=
located resources held by an object, leaving it in a safe state to be assig=
ned or destroyed.</div><div><br></div><div>Motivation: =C2=A0I want to comm=
unicate a value set in one thread and used in another. =C2=A0I'm thinki=
ng to write a class template, with 2 variables to hold the value, and to us=
e ping-pong buffering, to ease the atomicity issues of the setting thread c=
reating a new value for the using thread. =C2=A0I want to reset the old val=
ue when the using thread switches to the new value. =C2=A0The reset will sa=
fely release any dynamically-allocated resources used by the old value, but=
be optimized out for values of simpler types that don't have dynamical=
ly allocated resources.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/073535d5-6be5-4385-846d-e52291d38a1b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/073535d5-6be5-4385-846d-e52291d38a1b=
%40isocpp.org</a>.<br />
------=_Part_1523_705212607.1498415071377--
------=_Part_1522_421985346.1498415071377--
.
Author: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= <daniel.kruegler@gmail.com>
Date: Sun, 25 Jun 2017 20:37:00 +0200
Raw View
2017-06-25 20:24 GMT+02:00 'Walt Karas' via ISO C++ Standard - Future
Proposals <std-proposals@isocpp.org>:
> The reference implementation would be:
>
> template <typename T> reset(T &v) { T tmp{static_cast<T &&>(v)}; }
>
> It releases any dynamically-allocated resources held by an object, leaving
> it in a safe state to be assigned or destroyed.
What would it mean when T is a built-in pointer? How would reset
discriminate a pointer that owns or that doesn't own a resource? Is
reset to be intended to be a customization point? As you describe it
it sounds so trivial that I'm not sure why it would be worth
standardizing it. Could you elaborate a bit about realistic
optimization choices that could be realized by a Library
implementation but not by a third-party component that provides that
feature? Does there exists something like that in Boost or some other
library?
Thanks,
- Daniel
--
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/CAGNvRgCX%3DocqyveZ%2B9kxO895Ee-wfb2_o9y8aZNi19GfkLp8sA%40mail.gmail.com.
.
Author: "'Walt Karas' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Sun, 25 Jun 2017 11:45:36 -0700 (PDT)
Raw View
------=_Part_544_2012743698.1498416336791
Content-Type: multipart/alternative;
boundary="----=_Part_545_508836420.1498416336791"
------=_Part_545_508836420.1498416336791
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Primitive pointers owning resources is an unsolvable problem, with or=20
without this.
I think you are right, the only potential value of standardizing this is it=
=20
would be conveniently available to anyone with an installed compiler.
On Sunday, June 25, 2017 at 1:37:03 PM UTC-5, Daniel Kr=C3=BCgler wrote:
>
> 2017-06-25 20:24 GMT+02:00 'Walt Karas' via ISO C++ Standard - Future=20
> Proposals <std-pr...@isocpp.org <javascript:>>:=20
> > The reference implementation would be:=20
> >=20
> > template <typename T> reset(T &v) { T tmp{static_cast<T &&>(v)}; }=20
> >=20
> > It releases any dynamically-allocated resources held by an object,=20
> leaving=20
> > it in a safe state to be assigned or destroyed.=20
>
> What would it mean when T is a built-in pointer? How would reset=20
> discriminate a pointer that owns or that doesn't own a resource? Is=20
> reset to be intended to be a customization point? As you describe it=20
> it sounds so trivial that I'm not sure why it would be worth=20
> standardizing it. Could you elaborate a bit about realistic=20
> optimization choices that could be realized by a Library=20
> implementation but not by a third-party component that provides that=20
> feature? Does there exists something like that in Boost or some other=20
> library?=20
>
> Thanks,=20
>
> - Daniel=20
>
--=20
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 e=
mail 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/5708641c-422f-4747-b91c-593b2fbc90b1%40isocpp.or=
g.
------=_Part_545_508836420.1498416336791
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Primitive pointers owning resources is an unsolvable probl=
em, with or without this.<div><br></div><div>I think you are right, the onl=
y potential value of standardizing this is it would be conveniently availab=
le to anyone with an installed compiler.<br><br>On Sunday, June 25, 2017 at=
1:37:03 PM UTC-5, Daniel Kr=C3=BCgler wrote:<blockquote class=3D"gmail_quo=
te" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddi=
ng-left: 1ex;">2017-06-25 20:24 GMT+02:00 'Walt Karas' via ISO C++ =
Standard - Future
<br>Proposals <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-=
mailto=3D"XllRsGCjAQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'ja=
vascript:';return true;" onclick=3D"this.href=3D'javascript:';r=
eturn true;">std-pr...@isocpp.org</a>>:
<br>> The reference implementation would be:
<br>>
<br>> template <typename T> reset(T &v) { T tmp{static_cast<=
;T &&>(v)}; }
<br>>
<br>> It releases any dynamically-allocated resources held by an object,=
leaving
<br>> it in a safe state to be assigned or destroyed.
<br>
<br>What would it mean when T is a built-in pointer? How would reset
<br>discriminate a pointer that owns or that doesn't own a resource? Is
<br>reset to be intended to be a customization point? As you describe it
<br>it sounds so trivial that I'm not sure why it would be worth
<br>standardizing it. Could you elaborate a bit about realistic
<br>optimization choices that could be realized by a Library
<br>implementation but not by a third-party component that provides that
<br>feature? Does there exists something like that in Boost or some other
<br>library?
<br>
<br>Thanks,
<br>
<br>- Daniel
<br></blockquote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/5708641c-422f-4747-b91c-593b2fbc90b1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5708641c-422f-4747-b91c-593b2fbc90b1=
%40isocpp.org</a>.<br />
------=_Part_545_508836420.1498416336791--
------=_Part_544_2012743698.1498416336791--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 25 Jun 2017 12:19:21 -0700 (PDT)
Raw View
------=_Part_133_1371700924.1498418361566
Content-Type: multipart/alternative;
boundary="----=_Part_134_1000891256.1498418361567"
------=_Part_134_1000891256.1498418361567
Content-Type: text/plain; charset="UTF-8"
On Sunday, June 25, 2017 at 2:24:31 PM UTC-4, Walt Karas wrote:
>
> The reference implementation would be:
>
> template <typename T> reset(T &v) { T tmp{static_cast<T &&>(v)}; }
>
I think you're missing a `void` here.
It releases any dynamically-allocated resources held by an object, leaving
> it in a safe state to be assigned or destroyed.
>
> Motivation: I want to communicate a value set in one thread and used in
> another. I'm thinking to write a class template, with 2 variables to hold
> the value, and to use ping-pong buffering, to ease the atomicity issues of
> the setting thread creating a new value for the using thread. I want to
> reset the old value when the using thread switches to the new value. The
> reset will safely release any dynamically-allocated resources used by the
> old value, but be optimized out for values of simpler types that don't have
> dynamically allocated resources.
>
I'm not sure I see the need for a generic algorithm for doing this. If you
have some RAII object which may hold resources, you can try to empty it
with `Typename(std::move(object));` just fine. If `Typename` is trivially
copyable and moveable, then the compiler can know that this statement
results in nothing. Sure, you'll have to know the typename, but that's at
best a minor inconvenience.
I don't think this sort of thing comes up enough to warrant such a function.
--
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/0ace5f6a-f845-41a2-a2cd-715671b3b933%40isocpp.org.
------=_Part_134_1000891256.1498418361567
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, June 25, 2017 at 2:24:31 PM UTC-4, Walt Karas w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">The refe=
rence implementation would be:<div><br></div><div>template <typename T&g=
t; reset(T &v) { T tmp{static_cast<T &&>(v)}; }<br></div>=
</div></blockquote><div><br>I think you're missing a `void` here.<br><b=
r></div><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></div><div>It releases any dynamically-allocated resources held =
by an object, leaving it in a safe state to be assigned or destroyed.</div>=
<div><br></div><div>Motivation: =C2=A0I want to communicate a value set in =
one thread and used in another. =C2=A0I'm thinking to write a class tem=
plate, with 2 variables to hold the value, and to use ping-pong buffering, =
to ease the atomicity issues of the setting thread creating a new value for=
the using thread. =C2=A0I want to reset the old value when the using threa=
d switches to the new value. =C2=A0The reset will safely release any dynami=
cally-allocated resources used by the old value, but be optimized out for v=
alues of simpler types that don't have dynamically allocated resources.=
</div></div></blockquote><div><br>I'm not sure I see the need for a gen=
eric algorithm for doing this. If you have some RAII object which may hold =
resources, you can try to empty it with `Typename(std::move(object));` just=
fine. If `Typename` is trivially copyable and moveable, then the compiler =
can know that this statement results in nothing. Sure, you'll have to k=
now the typename, but that's at best a minor inconvenience.<br><br>I do=
n't think this sort of thing comes up enough to warrant such a function=
..<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/0ace5f6a-f845-41a2-a2cd-715671b3b933%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0ace5f6a-f845-41a2-a2cd-715671b3b933=
%40isocpp.org</a>.<br />
------=_Part_134_1000891256.1498418361567--
------=_Part_133_1371700924.1498418361566--
.