Topic: Some (more) comments on indirect<T>
Author: mihailnajdenov@gmail.com
Date: Wed, 26 Oct 2016 03:06:33 -0700 (PDT)
Raw View
------=_Part_999_297484964.1477476393367
Content-Type: multipart/alternative;
boundary="----=_Part_1000_918644583.1477476393367"
------=_Part_1000_918644583.1477476393367
Content-Type: text/plain; charset=UTF-8
This is a continuation
of https://groups.google.com/a/isocpp.org/d/msg/std-proposals/7rSMtvQVASk/PYmCgVfBAAAJ
* About the interface:*
- There should be a way to release the instance, much like a unique_ptr.
Not because some sort of symmetry, but because I must be able to
opt-out from the services of indirect<>.
If someone returns me and instance of this class, I must be able to convert
it to my types without a cost.
I might want to downgrade the return returned value to a regular unique_ptr
and disable incidental copies (for performance or sematic reasons).
I might want to make the returned data a shared_ptr<const T> and provide
just a read only "view" to it.
I might want to use my own "value-class" instead of indirect<>. In this
case I should also be able to get_deleter() and get_copier().
* About the implementation* (besides possible SOO):
- there is unused init() function.
- I *think* the base case, the one created with make_indirect, can be
removed from the overload set because there is no type erasure for it.
It can be an alternative to the control block instead.
something like
std::unique_ptr<std::variant<T, control_block<T>>> cb_;
So for the base case: T==U, default_deleter, default_copier
indirect<> will be basically zero cost, eliminating virtual function calls.
This can be taken further, adding a special case of a malloc-memcpy-free
combo as well - this will enable zero-cost, type-safe C-buffers with value
semantics.
std::variant <
std::unique_ptr<T>, //< default case
malloc_memcpy_free_block<T>, //< C-buffer-case
std::unique_ptr<control_block<T>> //< type-erased case
> cb_;
Of course, the impl. becomes considerably more involved.
--
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/b44e8e55-7079-4ebe-8d74-6ed5407f4266%40isocpp.org.
------=_Part_1000_918644583.1477476393367
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>This is a continuation of=C2=A0https://groups.google.=
com/a/isocpp.org/d/msg/std-proposals/7rSMtvQVASk/PYmCgVfBAAAJ</div><div><br=
></div><div><br></div><div><b>=C2=A0About the interface:</b></div><div><br>=
</div><div>=C2=A0- There should be a way to release the instance, much like=
a unique_ptr. </div><div>Not because some sort of symmetry, but because I =
must be able to opt-out=C2=A0from the services of indirect<>.</div><d=
iv><br></div><div>If someone returns me and instance of this class, I must =
be able to convert it to my types without a cost.</div><div><br></div><div>=
I might want to downgrade the=C2=A0return returned value to a regular uniqu=
e_ptr and disable incidental=C2=A0copies (for performance or sematic reason=
s).</div><div><br></div><div>I might want to make the returned data a=C2=A0=
shared_ptr<const T> and provide just a read only "view" to =
it.</div><div><br></div><div>I might want to use my own=C2=A0"value-cl=
ass" instead of indirect<>. In this case I should also=C2=A0be a=
ble to get_deleter() and get_copier().</div><div><br></div><div><br></div><=
div><br></div><div><b>=C2=A0About the implementation</b> (besides possible=
=C2=A0SOO):</div><div><br></div><div>=C2=A0- there is unused init() functio=
n. </div><div><br></div><div>=C2=A0- I <i>think</i> the base case, the one =
created with make_indirect, can be removed from the overload set because th=
ere is no type erasure for it.</div><div>It can be an alternative to the co=
ntrol block instead.</div><div><br></div><div>something like</div><div><div=
class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-=
wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span class=3D"styled-by-prettify" =
style=3D"color: #000;">std</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">::</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #000;">unique_ptr</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #660;"><</span><span class=3D"styled-by-prettify" style=3D"color: #00=
0;">std</span><span class=3D"styled-by-prettify" style=3D"color: #660;">::<=
/span><span class=3D"styled-by-prettify" style=3D"color: #000;">variant</sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;"><</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;">T</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">,</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"> control_block</span><span class=3D"s=
tyled-by-prettify" style=3D"color: #660;"><</span><span class=3D"styled-=
by-prettify" style=3D"color: #000;">T</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #660;">>>></span><span class=3D"styled-by-pret=
tify" style=3D"color: #000;"> cb_</span><span class=3D"styled-by-prettify" =
style=3D"color: #660;">;</span></div></code></div></div><div><br></div><div=
>So for the base case: T=3D=3DU, default_deleter, default_copier </div><div=
>indirect<> will be basically zero cost, eliminating=C2=A0virtual fun=
ction calls.</div><div><br></div><div>This can be taken further, adding a s=
pecial case of a malloc-memcpy-free combo as well - this will enable zero-c=
ost, type-safe C-buffers with value semantics.</div><div><br></div><div><di=
v class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word=
-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><span class=3D"styled-by-prettify"=
style=3D"color: #000;">std</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">::</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #000;">variant </span><span class=3D"styled-by-prettify" style=3D"color:=
#660;"><</span><span class=3D"styled-by-prettify" style=3D"color: #000;=
"><br>std</span><span class=3D"styled-by-prettify" style=3D"color: #660;">:=
:</span><span class=3D"styled-by-prettify" style=3D"color: #000;">unique_pt=
r</span><span class=3D"styled-by-prettify" style=3D"color: #660;"><</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #000;">T</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #660;">>,</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"style=
d-by-prettify" style=3D"color: #800;">//< default case</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"><br>malloc_memcpy_free_block=
</span><span class=3D"styled-by-prettify" style=3D"color: #660;"><</span=
><span class=3D"styled-by-prettify" style=3D"color: #000;">T</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: #660;">>,</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"style=
d-by-prettify" style=3D"color: #800;">//< C-buffer-case</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #000;"><br>std</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">::</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;">unique_ptr</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #660;"><</span><span class=3D"styled-by-=
prettify" style=3D"color: #000;">control_block</span><span class=3D"styled-=
by-prettify" style=3D"color: #660;"><</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #000;">T</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #660;">>></span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"colo=
r: #800;">//< type-erased case</span><span class=3D"styled-by-prettify" =
style=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">></span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;"> cb_</span><span class=3D"styled-by-prettify" style=3D"color: #=
660;">;</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br=
></span></div></code></div></div><div><br></div><div>Of course, the impl. b=
ecomes considerably more involved. </div><div><br></div><div><br></div></di=
v>
<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/b44e8e55-7079-4ebe-8d74-6ed5407f4266%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b44e8e55-7079-4ebe-8d74-6ed5407f4266=
%40isocpp.org</a>.<br />
------=_Part_1000_918644583.1477476393367--
------=_Part_999_297484964.1477476393367--
.
Author: Jonathan Coe <jbcoe@me.com>
Date: Wed, 26 Oct 2016 15:11:00 +0100
Raw View
--001a1147aa4cd47158053fc531ac
Content-Type: text/plain; charset=UTF-8
On 26 October 2016 at 11:06, <mihailnajdenov@gmail.com> wrote:
> This is a continuation of https://groups.google.com/
> a/isocpp.org/d/msg/std-proposals/7rSMtvQVASk/PYmCgVfBAAAJ
>
>
> * About the interface:*
>
> - There should be a way to release the instance, much like a unique_ptr.
> Not because some sort of symmetry, but because I must be able to
> opt-out from the services of indirect<>.
>
>
Adding `release` prevents us from doing a single allocation for the object
and control block (as done by `make_indirect`). LEWG picked combined
allocation over `release` when we discussed the previous incarnation in
Jacksonville.
note that `shared_ptr` lacks `release` for the same reason.
> If someone returns me and instance of this class, I must be able to
> convert it to my types without a cost.
>
> I might want to downgrade the return returned value to a regular
> unique_ptr and disable incidental copies (for performance or sematic
> reasons).
>
> I might want to make the returned data a shared_ptr<const T> and provide
> just a read only "view" to it.
>
> I might want to use my own "value-class" instead of indirect<>. In this
> case I should also be able to get_deleter() and get_copier().
>
>
>
> * About the implementation* (besides possible SOO):
>
>
My implementation is intended to be working proof of concept (and easy-ish
to read).
If you can post a PR(s) with efficiency improvements I'd be very keen to
incorporate it.
regards,
Jon
> - there is unused init() function.
>
> - I *think* the base case, the one created with make_indirect, can be
> removed from the overload set because there is no type erasure for it.
> It can be an alternative to the control block instead.
>
> something like
> std::unique_ptr<std::variant<T, control_block<T>>> cb_;
>
> So for the base case: T==U, default_deleter, default_copier
> indirect<> will be basically zero cost, eliminating virtual function calls.
>
> This can be taken further, adding a special case of a malloc-memcpy-free
> combo as well - this will enable zero-cost, type-safe C-buffers with value
> semantics.
>
> std::variant <
> std::unique_ptr<T>, //< default case
> malloc_memcpy_free_block<T>, //< C-buffer-case
> std::unique_ptr<control_block<T>> //< type-erased case
> > cb_;
>
> Of course, the impl. becomes considerably more involved.
>
>
> --
> 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/b44e8e55-7079-4ebe-
> 8d74-6ed5407f4266%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b44e8e55-7079-4ebe-8d74-6ed5407f4266%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CAAbBDD-MiQWq0JVT5ViCjd%3D577y8L3kvKyy-Y54nf2D1hOOfLQ%40mail.gmail.com.
--001a1147aa4cd47158053fc531ac
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><div class=3D"gmail_quote">=
On 26 October 2016 at 11:06, <span dir=3D"ltr"><<a href=3D"mailto:mihai=
lnajdenov@gmail.com" target=3D"_blank">mihailnajdenov@gmail.com</a>></sp=
an> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>This is =
a continuation of=C2=A0<a href=3D"https://groups.google.com/a/isocpp.org/d/=
msg/std-proposals/7rSMtvQVASk/PYmCgVfBAAAJ" target=3D"_blank">https://group=
s.google.com/<wbr>a/isocpp.org/d/msg/std-<wbr>proposals/7rSMtvQVASk/<wbr>PY=
mCgVfBAAAJ</a></div><div><br></div><div><br></div><div><b>=C2=A0About the i=
nterface:</b></div><div><br></div><div>=C2=A0- There should be a way to rel=
ease the instance, much like a unique_ptr. </div><div>Not because some sort=
of symmetry, but because I must be able to opt-out=C2=A0from the services =
of indirect<>.</div><div><br></div></div></blockquote><div><br></div>=
<div>Adding `release` prevents us from doing a single allocation for the ob=
ject and control block (as done by `make_indirect`). LEWG picked combined a=
llocation over `release` when we discussed the previous incarnation in Jack=
sonville.</div><div><br></div><div>note that `shared_ptr` lacks `release` f=
or the same reason.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote"=
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr"><div></div><div>If someone returns me and instance of this c=
lass, I must be able to convert it to my types without a cost.</div><div><b=
r></div><div>I might want to downgrade the=C2=A0return returned value to a =
regular unique_ptr and disable incidental=C2=A0copies (for performance or s=
ematic reasons).</div><div><br></div><div>I might want to make the returned=
data a=C2=A0shared_ptr<const T> and provide just a read only "v=
iew" to it.</div><div><br></div><div>I might want to use my own=C2=A0&=
quot;value-class" instead of indirect<>. In this case I should a=
lso=C2=A0be able to get_deleter() and get_copier().</div><div><br></div><di=
v><br></div><div><br></div><div><b>=C2=A0About the implementation</b> (besi=
des possible=C2=A0SOO):</div><div><br></div></div></blockquote><div><br></d=
iv><div>My implementation is intended to be working proof of concept (and e=
asy-ish to read).</div><div><br></div><div>If you can post a PR(s) with eff=
iciency improvements I'd be very keen to incorporate it.</div><div><br>=
</div><div>regards,</div><div><br></div><div>Jon</div><div>=C2=A0</div><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr"><div></div><div>=C2=A0- there i=
s unused init() function. </div><div><br></div><div>=C2=A0- I <i>think</i> =
the base case, the one created with make_indirect, can be removed from the =
overload set because there is no type erasure for it.</div><div>It can be a=
n alternative to the control block instead.</div><div><br></div><div>someth=
ing like</div><div><div class=3D"m_-2317433959157749640prettyprint" style=
=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color=
:rgb(250,250,250)"><code class=3D"m_-2317433959157749640prettyprint"><div c=
lass=3D"m_-2317433959157749640subprettyprint"><span class=3D"m_-23174339591=
57749640styled-by-prettify" style=3D"color:#000">std</span><span class=3D"m=
_-2317433959157749640styled-by-prettify" style=3D"color:#660">::</span><spa=
n class=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#000">u=
nique_ptr</span><span class=3D"m_-2317433959157749640styled-by-prettify" st=
yle=3D"color:#660"><</span><span class=3D"m_-2317433959157749640styled-b=
y-prettify" style=3D"color:#000">std</span><span class=3D"m_-23174339591577=
49640styled-by-prettify" style=3D"color:#660">::</span><span class=3D"m_-23=
17433959157749640styled-by-prettify" style=3D"color:#000">variant</span><sp=
an class=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#660">=
<</span><span class=3D"m_-2317433959157749640styled-by-prettify" style=
=3D"color:#000">T</span><span class=3D"m_-2317433959157749640styled-by-pret=
tify" style=3D"color:#660"><wbr>,</span><span class=3D"m_-23174339591577496=
40styled-by-prettify" style=3D"color:#000"> control_block</span><span class=
=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#660"><</sp=
an><span class=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:=
#000">T</span><span class=3D"m_-2317433959157749640styled-by-prettify" styl=
e=3D"color:#660">>>></span><span class=3D"m_-2317433959157749640st=
yled-by-prettify" style=3D"color:#000"> cb_</span><span class=3D"m_-2317433=
959157749640styled-by-prettify" style=3D"color:#660">;</span></div></code><=
/div></div><div><br></div><div>So for the base case: T=3D=3DU, default_dele=
ter, default_copier </div><div>indirect<> will be basically zero cost=
, eliminating=C2=A0virtual function calls.</div><div><br></div><div>This ca=
n be taken further, adding a special case of a malloc-memcpy-free combo as =
well - this will enable zero-cost, type-safe C-buffers with value semantics=
..</div><div><br></div><div><div class=3D"m_-2317433959157749640prettyprint"=
style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background=
-color:rgb(250,250,250)"><code class=3D"m_-2317433959157749640prettyprint">=
<div class=3D"m_-2317433959157749640subprettyprint"><span class=3D"m_-23174=
33959157749640styled-by-prettify" style=3D"color:#000">std</span><span clas=
s=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#660">::</spa=
n><span class=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#=
000">variant </span><span class=3D"m_-2317433959157749640styled-by-prettify=
" style=3D"color:#660"><</span><span class=3D"m_-2317433959157749640styl=
ed-by-prettify" style=3D"color:#000"><br>std</span><span class=3D"m_-231743=
3959157749640styled-by-prettify" style=3D"color:#660">::</span><span class=
=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#000">unique_p=
tr</span><span class=3D"m_-2317433959157749640styled-by-prettify" style=3D"=
color:#660"><</span><span class=3D"m_-2317433959157749640styled-by-prett=
ify" style=3D"color:#000">T</span><span class=3D"m_-2317433959157749640styl=
ed-by-prettify" style=3D"color:#660">>,</span><span class=3D"m_-23174339=
59157749640styled-by-prettify" style=3D"color:#000"> </span><span class=3D"=
m_-2317433959157749640styled-by-prettify" style=3D"color:#800">//< defau=
lt case</span><span class=3D"m_-2317433959157749640styled-by-prettify" styl=
e=3D"color:#000"><br>malloc_memcpy_free_block</span><span class=3D"m_-23174=
33959157749640styled-by-prettify" style=3D"color:#660"><</span><span cla=
ss=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#000">T</spa=
n><span class=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#=
660">>,</span><span class=3D"m_-2317433959157749640styled-by-prettify" s=
tyle=3D"color:#000"> </span><span class=3D"m_-2317433959157749640styled-by-=
prettify" style=3D"color:#800">//< C-buffer-case</span><span class=3D"m_=
-2317433959157749640styled-by-prettify" style=3D"color:#000"><br>std</span>=
<span class=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#66=
0">::</span><span class=3D"m_-2317433959157749640styled-by-prettify" style=
=3D"color:#000">unique_ptr</span><span class=3D"m_-2317433959157749640style=
d-by-prettify" style=3D"color:#660"><</span><span class=3D"m_-2317433959=
157749640styled-by-prettify" style=3D"color:#000">control_block</span><span=
class=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#660">&l=
t;</span><span class=3D"m_-2317433959157749640styled-by-prettify" style=3D"=
color:#000"><wbr>T</span><span class=3D"m_-2317433959157749640styled-by-pre=
ttify" style=3D"color:#660">>></span><span class=3D"m_-23174339591577=
49640styled-by-prettify" style=3D"color:#000"> </span><span class=3D"m_-231=
7433959157749640styled-by-prettify" style=3D"color:#800">//< type-erased=
case</span><span class=3D"m_-2317433959157749640styled-by-prettify" style=
=3D"color:#000"><br></span><span class=3D"m_-2317433959157749640styled-by-p=
rettify" style=3D"color:#660">></span><span class=3D"m_-2317433959157749=
640styled-by-prettify" style=3D"color:#000"> cb_</span><span class=3D"m_-23=
17433959157749640styled-by-prettify" style=3D"color:#660">;</span><span cla=
ss=3D"m_-2317433959157749640styled-by-prettify" style=3D"color:#000"><br></=
span></div></code></div></div><div><br></div><div>Of course, the impl. beco=
mes considerably more involved. </div><span class=3D"HOEnZb"><font color=3D=
"#888888"><div><br></div><div><br></div></font></span></div><span class=3D"=
HOEnZb"><font color=3D"#888888">
<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" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>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/b44e8e55-7079-4ebe-8d74-6ed5407f4266%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/b44e=
8e55-7079-4ebe-<wbr>8d74-6ed5407f4266%40isocpp.org</a><wbr>.<br>
</font></span></blockquote></div><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/CAAbBDD-MiQWq0JVT5ViCjd%3D577y8L3kvKy=
y-Y54nf2D1hOOfLQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAAbBDD-MiQWq0J=
VT5ViCjd%3D577y8L3kvKyy-Y54nf2D1hOOfLQ%40mail.gmail.com</a>.<br />
--001a1147aa4cd47158053fc531ac--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 26 Oct 2016 17:16:38 +0300
Raw View
On 26 October 2016 at 17:11, Jonathan Coe <jbcoe@me.com> wrote:
> Adding `release` prevents us from doing a single allocation for the object
> and control block (as done by `make_indirect`). LEWG picked combined
> allocation over `release` when we discussed the previous incarnation in
> Jacksonville.
>
> note that `shared_ptr` lacks `release` for the same reason.
shared_ptr lacks a release() because you can't release shared
ownership from one shared owner.
The possibility of a combined allocation just makes it harder, but is
not the main reason.
--
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/CAFk2RUZA6wW%2ByHbXpP2Q2pn%3DbkxW8Mfy7K4UhFsbGjnu%3DbRUtw%40mail.gmail.com.
.
Author: Jonathan Coe <jbcoe@me.com>
Date: Wed, 26 Oct 2016 15:19:21 +0100
Raw View
--94eb2c034bfcb3fbd2053fc54f01
Content-Type: text/plain; charset=UTF-8
On 26 October 2016 at 15:16, Ville Voutilainen <ville.voutilainen@gmail.com>
wrote:
> On 26 October 2016 at 17:11, Jonathan Coe <jbcoe@me.com> wrote:
> > Adding `release` prevents us from doing a single allocation for the
> object
> > and control block (as done by `make_indirect`). LEWG picked combined
> > allocation over `release` when we discussed the previous incarnation in
> > Jacksonville.
> >
> > note that `shared_ptr` lacks `release` for the same reason.
>
> shared_ptr lacks a release() because you can't release shared
> ownership from one shared owner.
> The possibility of a combined allocation just makes it harder, but is
> not the main reason.
>
>
True, for shared_ptr it's a logical rather than implementation restriction.
If we can see how to implement `release` for `indirect` (and keep the
combined allocation) then I see no reason not to add it.
> --
> 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/CAFk2RUZA6wW%2ByHbXpP2Q2pn%
> 3DbkxW8Mfy7K4UhFsbGjnu%3DbRUtw%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/CAAbBDD-RWYZw4AUDuG_SOHduuoxXLvPGYn1xvQNj%2BecQgirRzA%40mail.gmail.com.
--94eb2c034bfcb3fbd2053fc54f01
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On 26 October 2016 at 15:16, Ville Voutilainen <span dir=
=3D"ltr"><<a href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_blan=
k">ville.voutilainen@gmail.com</a>></span> wrote:<br><div class=3D"gmail=
_extra"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span cl=
ass=3D"">On 26 October 2016 at 17:11, Jonathan Coe <<a href=3D"mailto:jb=
coe@me.com">jbcoe@me.com</a>> wrote:<br>
> Adding `release` prevents us from doing a single allocation for the ob=
ject<br>
> and control block (as done by `make_indirect`). LEWG picked combined<b=
r>
> allocation over `release` when we discussed the previous incarnation i=
n<br>
> Jacksonville.<br>
><br>
> note that `shared_ptr` lacks `release` for the same reason.<br>
<br>
</span>shared_ptr lacks a release() because you can't release shared<br=
>
ownership from one shared owner.<br>
The possibility of a combined allocation just makes it harder, but is<br>
not the main reason.<br>
<span class=3D""><br></span></blockquote><div><br></div><div>True, for shar=
ed_ptr it's a logical rather than implementation restriction.=C2=A0</di=
v><div>If we can see how to implement `release` for `indirect` (and keep th=
e combined allocation) then I see no reason not to add it.</div><div>=C2=A0=
</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><span class=3D"">
--<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%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@<wbr>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>
</span>To view this discussion on the web visit <a href=3D"https://groups.g=
oogle.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUZA6wW%2ByHbXpP2Q2pn%3Db=
kxW8Mfy7K4UhFsbGjnu%3DbRUtw%40mail.gmail.com" rel=3D"noreferrer" target=3D"=
_blank">https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>propos=
als/CAFk2RUZA6wW%<wbr>2ByHbXpP2Q2pn%<wbr>3DbkxW8Mfy7K4UhFsbGjnu%<wbr>3DbRUt=
w%40mail.gmail.com</a>.<br>
</blockquote></div><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/CAAbBDD-RWYZw4AUDuG_SOHduuoxXLvPGYn1x=
vQNj%2BecQgirRzA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAAbBDD-RWYZw4A=
UDuG_SOHduuoxXLvPGYn1xvQNj%2BecQgirRzA%40mail.gmail.com</a>.<br />
--94eb2c034bfcb3fbd2053fc54f01--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 26 Oct 2016 17:30:10 +0300
Raw View
On 26 October 2016 at 17:19, Jonathan Coe <jbcoe@me.com> wrote:
> True, for shared_ptr it's a logical rather than implementation restriction.
> If we can see how to implement `release` for `indirect` (and keep the
> combined allocation) then I see no reason not to add it.
I don't see how that could be achieved. The combined object that holds
both the deleter
and the object inside it would need to be exposed, and that's an
implementation-internal
type. Ripping apart the pointer and the deleter once they have been
combined is not possible.
--
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/CAFk2RUbwOhqwjj-o2Zc9JznKGJrC8nn_KbZmMCh8eKN%3Dj42bMA%40mail.gmail.com.
.
Author: Jonathan Coe <jbcoe@me.com>
Date: Wed, 26 Oct 2016 15:48:41 +0100
Raw View
--001a1147aa4c9f49ff053fc5b871
Content-Type: text/plain; charset=UTF-8
On 26 October 2016 at 15:30, Ville Voutilainen <ville.voutilainen@gmail.com>
wrote:
> On 26 October 2016 at 17:19, Jonathan Coe <jbcoe@me.com> wrote:
> > True, for shared_ptr it's a logical rather than implementation
> restriction.
> > If we can see how to implement `release` for `indirect` (and keep the
> > combined allocation) then I see no reason not to add it.
>
> I don't see how that could be achieved. The combined object that holds
> both the deleter
> and the object inside it would need to be exposed, and that's an
> implementation-internal
> type. Ripping apart the pointer and the deleter once they have been
> combined is not possible.
>
>
That was my impression too.
> --
> 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/CAFk2RUbwOhqwjj-
> o2Zc9JznKGJrC8nn_KbZmMCh8eKN%3Dj42bMA%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/CAAbBDD_0j0CKL-%3DwaEYLQVBDtkPduwLfxTYgoM%2BVjSJzqZNYcQ%40mail.gmail.com.
--001a1147aa4c9f49ff053fc5b871
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On 26 October 2016 at 15:30, Ville Voutilainen <span dir=
=3D"ltr"><<a href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_blan=
k">ville.voutilainen@gmail.com</a>></span> wrote:<br><div class=3D"gmail=
_extra"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span cl=
ass=3D"">On 26 October 2016 at 17:19, Jonathan Coe <<a href=3D"mailto:jb=
coe@me.com">jbcoe@me.com</a>> wrote:<br>
> True, for shared_ptr it's a logical rather than implementation res=
triction.<br>
> If we can see how to implement `release` for `indirect` (and keep the<=
br>
> combined allocation) then I see no reason not to add it.<br>
<br>
</span>I don't see how that could be achieved. The combined object that=
holds<br>
both the deleter<br>
and the object inside it would need to be exposed, and that's an<br>
implementation-internal<br>
type. Ripping apart the pointer and the deleter once they have been<br>
combined is not possible.<br>
<span class=3D""><br></span></blockquote><div><br></div><div>That was my im=
pression too.</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span cl=
ass=3D"">
--<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%2Bunsubscribe@isocpp.org">std-propo=
sals+unsubscribe@<wbr>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>
</span>To view this discussion on the web visit <a href=3D"https://groups.g=
oogle.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUbwOhqwjj-o2Zc9JznKGJrC8=
nn_KbZmMCh8eKN%3Dj42bMA%40mail.gmail.com" rel=3D"noreferrer" target=3D"_bla=
nk">https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/=
CAFk2RUbwOhqwjj-<wbr>o2Zc9JznKGJrC8nn_KbZmMCh8eKN%<wbr>3Dj42bMA%40mail.gmai=
l.com</a>.<br>
</blockquote></div><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/CAAbBDD_0j0CKL-%3DwaEYLQVBDtkPduwLfxT=
YgoM%2BVjSJzqZNYcQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAAbBDD_0j0CK=
L-%3DwaEYLQVBDtkPduwLfxTYgoM%2BVjSJzqZNYcQ%40mail.gmail.com</a>.<br />
--001a1147aa4c9f49ff053fc5b871--
.
Author: mihailnajdenov@gmail.com
Date: Wed, 26 Oct 2016 08:11:36 -0700 (PDT)
Raw View
------=_Part_1888_1905648108.1477494696776
Content-Type: multipart/alternative;
boundary="----=_Part_1889_1805456034.1477494696776"
------=_Part_1889_1805456034.1477494696776
Content-Type: text/plain; charset=UTF-8
First, let me point a use case where "release" will be needed
LulzFile file;
indirect<char> LulzFile::readAll();
This use case is not unreasonable at all - any easy one-call to read it
all, giving me the data. Copy of this data is well-defined, so no real
reason to pick unique_ptr instead.
I will hate this guy however, because indirect<> will slip into my code
unwanted (OR I suffer the word most avoidable copy OR I use some low level
API to fill a user supplied container).
This case is based on real life - QByteArray QFile::readAll() is very
annoying in insisting one must use QByteArray for the rest of the life of
the data.
As for the control block being allocated as part of the object for the
make_indirect.
As I said, I am 99% sure, the base case can go without a control block and
be a separate case as no type erasure is need.
The other cases already do a separate alloc.
I might try things out to see where it goes, mainly to se how conversions
will work.
P.S. unified alloc over release() is not a good decision IMO - it will make
the user scream, when he needs the data *only* NOT *the package!*
Also, unless I am missing something, the control block can be made part of
the instance and be small object optimized?
This control object has nothing to do with the shared_ptr one - it is tiny,
simple and bound to the instance itself.
--
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/91857f39-41d4-4ac9-867a-3caba15ee40a%40isocpp.org.
------=_Part_1889_1805456034.1477494696776
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>First, let me point a use case where "release&qu=
ot; will be needed</div><div><br></div><div class=3D"prettyprint" style=3D"=
border: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-col=
or: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprett=
yprint"><span class=3D"styled-by-prettify" style=3D"color: #606;">LulzFile<=
/span><span class=3D"styled-by-prettify" style=3D"color: #000;"> file</span=
><span class=3D"styled-by-prettify" style=3D"color: #660;">;</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: #000;"><br><br>indirect</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #080;"><char></span>=
<span class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #606;">LulzFile</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">::</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;">readAll</span><span class=3D"styled-=
by-prettify" style=3D"color: #660;">();</span><span class=3D"styled-by-pret=
tify" style=3D"color: #000;"><br></span></div></code></div><div><br></div><=
div><br></div><div>This use case is not unreasonable at all - any easy one-=
call to read it all, giving me the data. Copy=C2=A0of this data is well-def=
ined, so no real reason to pick unique_ptr instead.</div><div><br></div><di=
v>I will hate this guy however, because indirect<> will slip into my =
code unwanted (OR I suffer the word most avoidable copy OR I use some low l=
evel API to fill a user supplied container).</div><div><br></div><div>This =
case is based on real life -=C2=A0QByteArray QFile::<span class=3D"styled-b=
y-prettify" style=3D"color: #000;">readAll() is very annoying in insisting =
one must use QByteArray for the rest of the life of the data. </span></div>=
<div><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><=
/div><div><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></s=
pan></div><div><span class=3D"styled-by-prettify" style=3D"color: #000;">As=
for the control block being allocated as part of the object for the make_i=
ndirect. </span></div><div><span class=3D"styled-by-prettify" style=3D"colo=
r: #000;">As I said, I am=C2=A099% sure, the base case can go without a con=
trol block and be a separate case as no type erasure is need.=C2=A0=C2=A0</=
span></div><div><span class=3D"styled-by-prettify" style=3D"color: #000;">T=
he other cases already do a separate alloc.</span></div><div><br></div><div=
>I might try things out to see where it goes, mainly to se how conversions =
will work. </div><div><br></div><div><br></div><div>P.S. unified alloc over=
release()=C2=A0is not a good decision IMO - it will make the user scream, =
when he needs the data <i>only</i> NOT <i>the package!</i> </div><div>Also,=
unless I am missing something, the=C2=A0control block can be made part of =
the instance and=C2=A0be small object optimized?=C2=A0=C2=A0=C2=A0</div><di=
v>This control object has nothing to do with the shared_ptr one - it is tin=
y, simple and bound to the instance itself. =C2=A0</div><div><br></div></di=
v>
<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/91857f39-41d4-4ac9-867a-3caba15ee40a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/91857f39-41d4-4ac9-867a-3caba15ee40a=
%40isocpp.org</a>.<br />
------=_Part_1889_1805456034.1477494696776--
------=_Part_1888_1905648108.1477494696776--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 26 Oct 2016 18:26:35 +0300
Raw View
On 26 October 2016 at 18:11, <mihailnajdenov@gmail.com> wrote:
> First, let me point a use case where "release" will be needed
>
> LulzFile file;
>
> indirect<char> LulzFile::readAll();
>
>
> This use case is not unreasonable at all - any easy one-call to read it all,
> giving me the data. Copy of this data is well-defined, so no real reason to
> pick unique_ptr instead.
>
> I will hate this guy however, because indirect<> will slip into my code
> unwanted (OR I suffer the word most avoidable copy OR I use some low level
> API to fill a user supplied container).
>
> This case is based on real life - QByteArray QFile::readAll() is very
> annoying in insisting one must use QByteArray for the rest of the life of
> the data.
Well, yes, I agree that a release() is so useful that I think that
should trump the desire
to do combined allocation. LEWG disagrees with that, but LEWG is wrong.
> Also, unless I am missing something, the control block can be made part of
> the instance and be small object optimized?
> This control object has nothing to do with the shared_ptr one - it is tiny,
> simple and bound to the instance itself.
I don't think so. The control object type-erases the cloner and the deleter.
--
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/CAFk2RUbBEz7-yoQbq2xOi-bQ_SY2D%2BMsn6whn_C%2BeV-MFSgnsA%40mail.gmail.com.
.
Author: mihailnajdenov@gmail.com
Date: Wed, 26 Oct 2016 08:58:19 -0700 (PDT)
Raw View
------=_Part_16_1849071630.1477497499358
Content-Type: multipart/alternative;
boundary="----=_Part_17_1210246651.1477497499358"
------=_Part_17_1210246651.1477497499358
Content-Type: text/plain; charset=UTF-8
On Wednesday, October 26, 2016 at 6:26:39 PM UTC+3, Ville Voutilainen wrote:
>
> ...
> > Also, unless I am missing something, the control block can be made part
> of
> > the instance and be small object optimized?
> > This control object has nothing to do with the shared_ptr one - it is
> tiny,
> > simple and bound to the instance itself.
>
> I don't think so. The control object type-erases the cloner and the
> deleter.
>
But these are tiny in 99% of the cases as they rarely if ever have
variables or captures.
sizeof pointer_control_block now is 24 - even std::string is bigger than
that.
These 24 can probably be reduced further with a custom vtable.
In any case, the key here is, the control_block is part of the instance by
definition - this gives huge room for tricks compared to shared_ptr.
--
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/258f616b-6149-42a0-8ec5-53b83215b270%40isocpp.org.
------=_Part_17_1210246651.1477497499358
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, October 26, 2016 at 6:26:39 PM UTC+3=
, Ville Voutilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin=
: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">...<=
br>> Also, unless I am missing something, the control block can be made =
part of
<br>> the instance and be small object optimized?
<br>> This control object has nothing to do with the shared_ptr one - it=
is tiny,
<br>> simple and bound to the instance itself.
<br>
<br>I don't think so. The control object type-erases the cloner and the=
deleter.
<br></blockquote><div><br></div><div>But these are tiny in 99% of the cases=
as they <span>rarely if ever=C2=A0</span>have variables or captures.=C2=A0=
</div><div>sizeof pointer_control_block now=C2=A0is 24 -=C2=A0even std::str=
ing is bigger than that. =C2=A0=C2=A0</div><div>These 24 can probably be re=
duced further with a custom vtable. </div><div><br></div><div>In any case, =
the key here=C2=A0is, the control_block is part of the instance by definiti=
on - this gives huge room for tricks compared to shared_ptr. </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/258f616b-6149-42a0-8ec5-53b83215b270%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/258f616b-6149-42a0-8ec5-53b83215b270=
%40isocpp.org</a>.<br />
------=_Part_17_1210246651.1477497499358--
------=_Part_16_1849071630.1477497499358--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 26 Oct 2016 19:09:08 +0300
Raw View
On 26 October 2016 at 18:58, <mihailnajdenov@gmail.com> wrote:>> >
Also, unless I am missing something, the control block can be made
part
>> > of
>> > the instance and be small object optimized?
>> > This control object has nothing to do with the shared_ptr one - it is
>> > tiny,
>> > simple and bound to the instance itself.
>>
>> I don't think so. The control object type-erases the cloner and the
>> deleter.
>
>
> But these are tiny in 99% of the cases as they rarely if ever have variables
> or captures.
> sizeof pointer_control_block now is 24 - even std::string is bigger than
> that.
> These 24 can probably be reduced further with a custom vtable.
That's a decent point, and certainly worth exploring implementation-wise.
> In any case, the key here is, the control_block is part of the instance by
> definition - this gives huge room for tricks compared to shared_ptr.
That's certainly true.
--
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/CAFk2RUYyCte2U5xH%3DW_W-jDCY-XqEj1LZ1%3DydZ6wSNPhsL%2BY-Q%40mail.gmail.com.
.
Author: mihailnajdenov@gmail.com
Date: Wed, 26 Oct 2016 12:49:04 -0700 (PDT)
Raw View
------=_Part_1944_291284803.1477511344655
Content-Type: multipart/alternative;
boundary="----=_Part_1945_1233214845.1477511344656"
------=_Part_1945_1233214845.1477511344656
Content-Type: text/plain; charset=UTF-8
Here is a poor man's hack to remove base case (std alloc, copy and delete)
from the type-erased overloaded cases.
template <typename T>
struct default_copier
{
T* operator()(const T& t) const
{
return new T(t);
}
};
template <typename T>
struct default_deleter
{
void operator()(const T* t) const
{
delete t;
}
};
template <typename T>
struct control_block
{
virtual ~control_block() = default;
virtual std::unique_ptr<control_block> clone() const = 0;
virtual T* ptr() = 0;
};
template <typename T, typename U, typename C = default_copier<U>,
typename D = default_deleter<U>>
class pointer_control_block : public control_block<T>
{
std::unique_ptr<U, D> p_;
C c_;
public:
explicit pointer_control_block(U* u, C c = C{}, D d = D{})
: p_(u, std::move(d))
, c_(std::move(c))
{
}
std::unique_ptr<control_block<T>> clone() const override
{
assert(p_);
return std::make_unique<pointer_control_block>(c_(*p_), c_,
p_.get_deleter());
}
T* ptr() override
{
return p_.get();
}
};
template <typename T, typename U>
class delegating_control_block : public control_block<T>
{
std::variant <
std::unique_ptr<U>
, std::unique_ptr<control_block<U>>
> delegate_;
public:
explicit delegating_control_block(std::variant <
std::unique_ptr<U>
, std::unique_ptr<control_block<U>>
> b)
: delegate_(std::move(b))
{}
std::unique_ptr<control_block<T>> clone() const override
{
if(delegate_.index() == 0)
{
return
std::make_unique<delegating_control_block>(std::make_unique<U>(*std::get<0>(delegate_)));
}
else
{
return
std::make_unique<delegating_control_block>(std::get<1>(delegate_)->clone());
}
}
T* ptr() override
{
return delegate_.index() == 0 ? std::get<0>(delegate_).get() :
std::get<1>(delegate_)->ptr();
}
};
template <typename T>
struct indirect
{
template <typename U>
friend class indirect;
template <typename T_, typename... Ts>
friend indirect<T_> make_indirect(Ts&&... ts);
T* ptr_ = nullptr;
std::variant <
std::unique_ptr<T>
, std::unique_ptr<control_block<T>>
> cb_;
indirect() = default;
template <typename U,
typename C = default_copier<U>,
typename D = default_deleter<U>,
typename V = std::enable_if_t<std::is_convertible<U*,
T*>::value>>
explicit indirect(U* u, C copier = C{}, D deleter = D{})
{
if (!u)
{
return;
}
assert(typeid(*u) == typeid(U));
// TODO: detect base case and use make_indirect-style alloc!
cb_ = std::make_unique<pointer_control_block<T, U, C, D>>(u,
std::move(copier),
std::move(deleter));
ptr_ = u;
}
explicit operator bool() const { return ptr_ != nullptr; }
//
// Copy-constructors
//
indirect(const indirect& p)
{
if (!p)
{
return;
}
if(p.cb_.index() == 0) //< TODO: use make_inderect
{
auto tmp_cb = std::make_unique<T>(*std::get<0>(p.cb_));
ptr_ = std::get<0>(p.cb_).get();
cb_ = std::move(tmp_cb);
}
else
{
auto tmp_cb = std::get<1>(p.cb_)->clone();
ptr_ = tmp_cb->ptr();
cb_ = std::move(tmp_cb);
}
}
template <typename U,
typename V = std::enable_if_t<!std::is_same<T, U>::value &&
std::is_convertible<U*,
T*>::value>>
indirect(const indirect<U>& p)
{
indirect<U> tmp(p);
ptr_ = tmp.ptr_;
cb_ = std::make_unique<delegating_control_block<T,
U>>(std::move(tmp.cb_));
}
};
template <typename T, typename... Ts>
indirect<T> make_indirect(Ts&&... ts)
{
indirect<T> p;
p.cb_ = std::make_unique<T>(std::forward<Ts>(ts)...);
p.ptr_ = std::get<0>(p.cb_).get();
return p;
}
The above can be compiled, though most of the impl is missing.
This makes the base case a special case and is as fast as hand-written
copyable unique_ptr.
If a converting assign is made ( A a1 = b where b is class B : A) the
subsequent assignments (A a2 = a1) will still be faster, because they do 1
instead of 2 virtual calls.
This virtual function call can probably be eliminated as well (for the base
case), but for now I am reusing delegating_control_block.
Currently only make_indirect creates the base case, all else falls back to
pointer_control_block . This can be improved, as well as probably much else.
--
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/20f19d5f-697a-4560-b27a-87949bd6c804%40isocpp.org.
------=_Part_1945_1233214845.1477511344656
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Here is a poor man's hack to remove base case (st=
d alloc, copy and delete) from the type-erased=C2=A0overloaded cases.</div>=
<div><br></div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(18=
7, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"=
><code class=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"r=
gb(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;"><br>t=
emplate <typename T><br>struct default_copier<br>{<br>=C2=A0 T* opera=
tor()(const T& t) const<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 return new T(=
t);<br>=C2=A0 }<br>};</font></div><div><br></div><div class=3D"subprettypri=
nt"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color:=
transparent;">template <typename T><br>struct default_deleter<br>{<b=
r>=C2=A0 void operator()(const T* t) const<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=
=A0 delete t;<br>=C2=A0 }<br>};</font></div><div><br></div><div class=3D"su=
bprettyprint"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"backgro=
und-color: transparent;">template <typename T><br>struct control_bloc=
k<br>{<br>=C2=A0 virtual ~control_block() =3D default;<br>=C2=A0 virtual st=
d::unique_ptr<control_block> clone() const =3D 0;<br>=C2=A0 virtual T=
* ptr() =3D 0;<br>};</font></div><div><br></div><div class=3D"subprettyprin=
t"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: =
transparent;">template <typename T, typename U, typename C =3D default_c=
opier<U>,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 t=
ypename D =3D default_deleter<U>><br>class pointer_control_block :=
public control_block<T><br>{<br>=C2=A0 std::unique_ptr<U, D> p=
_;<br>=C2=A0 C c_;</font></div><div><br></div><div class=3D"subprettyprint"=
><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: tr=
ansparent;">public:<br>=C2=A0 explicit pointer_control_block(U* u, C c =3D =
C{}, D d =3D D{})<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : p_(u, std::move(d))<b=
r>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 , c_(std::move(c))<br>=C2=A0 {<br>=C2=A0 }=
</font></div><div><br></div><div class=3D"subprettyprint"><font color=3D"rg=
b(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;">=C2=A0=
std::unique_ptr<control_block<T>> clone() const override<br>=
=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 assert(p_);<br>=C2=A0=C2=A0=C2=A0 return std=
::make_unique<pointer_control_block>(c_(*p_), c_, p_.get_deleter());<=
br>=C2=A0 }</font></div><div><br></div><div class=3D"subprettyprint"><font =
color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transpare=
nt;">=C2=A0 T* ptr() override<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 return p_.g=
et();<br>=C2=A0 }<br>};</font></div><div><br></div><div class=3D"subprettyp=
rint"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-colo=
r: transparent;">template <typename T, typename U><br>class delegatin=
g_control_block : public control_block<T><br>{<br>=C2=A0=C2=A0 std::v=
ariant <<br>=C2=A0=C2=A0=C2=A0 std::unique_ptr<U><br>=C2=A0=C2=A0=
=C2=A0 , std::unique_ptr<control_block<U>><br>=C2=A0=C2=A0=C2=
=A0 > delegate_;</font></div><div><br></div><div class=3D"subprettyprint=
"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: t=
ransparent;">public:<br>=C2=A0 explicit delegating_control_block(std::varia=
nt <<br>=C2=A0=C2=A0=C2=A0 std::unique_ptr<U><br>=C2=A0=C2=A0=C2=
=A0 , std::unique_ptr<control_block<U>><br>=C2=A0=C2=A0=C2=A0 &=
gt; b)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 : delegate_(std::move(b))<br>=C2=
=A0 {}</font></div><div><br></div><div class=3D"subprettyprint"><font color=
=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;">=
=C2=A0 std::unique_ptr<control_block<T>> clone() const override=
<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0 if(delegate_.index() =3D=3D 0)<br>=
=C2=A0=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return s=
td::make_unique<delegating_control_block>(std::make_unique<U>(*=
std::get<0>(delegate_)));<br>=C2=A0=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=
=A0=C2=A0=C2=A0 else<br>=C2=A0=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 return std::make_unique<delegating_control_block>(std=
::get<1>(delegate_)->clone());<br>=C2=A0=C2=A0=C2=A0=C2=A0 }<br>=
=C2=A0 }</font></div><div><br></div><div class=3D"subprettyprint"><font col=
or=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;=
">=C2=A0 T* ptr() override<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 return delegat=
e_.index() =3D=3D 0 ? std::get<0>(delegate_).get() : std::get<1>=
;(delegate_)->ptr();<br>=C2=A0 }<br>};</font></div><div><br></div><div c=
lass=3D"subprettyprint"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=
=3D"background-color: transparent;"><br>template <typename T><br>stru=
ct indirect<br>{<br>=C2=A0 template <typename U><br>=C2=A0 friend cla=
ss indirect;<br>=C2=A0 template <typename T_, typename... Ts><br>=C2=
=A0 friend indirect<T_> make_indirect(Ts&&... ts);</font></di=
v><div><br></div><div class=3D"subprettyprint"><font color=3D"rgb(34,34,34)=
" face=3D"Arial" style=3D"background-color: transparent;">=C2=A0 T* ptr_ =
=3D nullptr;</font></div><div><br></div><div class=3D"subprettyprint"><font=
color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transpar=
ent;">=C2=A0 std::variant <<br>=C2=A0=C2=A0=C2=A0 std::unique_ptr<T&g=
t;<br>=C2=A0=C2=A0 , std::unique_ptr<control_block<T>><br>=C2=
=A0 > cb_;<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0 indirect() =3D default;</fon=
t></div><div><br></div><div class=3D"subprettyprint"><font color=3D"rgb(34,=
34,34)" face=3D"Arial" style=3D"background-color: transparent;">=C2=A0 temp=
late <typename U, <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 typename C =3D default_copier<U>,<br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 typename D =3D defau=
lt_deleter<U>,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 typename V =3D std::enable_if_t<std::is_convertible<U=
*, T*>::value>><br>=C2=A0 explicit indirect(U* u, C copier =3D C{}=
, D deleter =3D D{})<br>=C2=A0{<br>=C2=A0=C2=A0=C2=A0 if (!u)<br>=C2=A0=C2=
=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return;<br>=C2=A0=C2=A0=C2=A0=
}</font></div><div><br></div><div class=3D"subprettyprint"><font color=3D"=
rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;">=C2=
=A0=C2=A0=C2=A0 assert(typeid(*u) =3D=3D typeid(U));<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <b=
r>=C2=A0=C2=A0=C2=A0 // TODO: detect base case and use make_indirect-style =
alloc!</font></div><div><br></div><div class=3D"subprettyprint"><font color=
=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;">=
=C2=A0=C2=A0=C2=A0 cb_ =3D std::make_unique<pointer_control_block<T, =
U, C, D>>(u, std::move(copier),<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 std::move(deleter));<br>=C2=A0=C2=A0=C2=A0 ptr_ =3D u;<br>=
=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0 explicit operator bool() const { =
return ptr_ !=3D nullptr; }</font></div><div><br></div><div class=3D"subpre=
ttyprint"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-=
color: transparent;">=C2=A0 //<br>=C2=A0 // Copy-constructors<br>=C2=A0 //<=
/font></div><div><br></div><div class=3D"subprettyprint"><font color=3D"rgb=
(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;">=C2=A0 =
indirect(const indirect& p)<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 if (!p)<b=
r>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return;<br>=C2=A0=
=C2=A0=C2=A0 }</font></div><div><br></div><div class=3D"subprettyprint"><fo=
nt color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transp=
arent;">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if(p.cb_.index() =3D=3D 0) //< TO=
DO: use make_inderect<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto tmp_cb =3D std::make_unique<T>(*s=
td::get<0>(p.cb_));<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ptr=
_ =3D std::get<0>(p.cb_).get();<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 cb_ =3D std::move(tmp_cb);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }<br=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {<br=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto tmp_cb =3D std::get&=
lt;1>(p.cb_)->clone();<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 ptr_ =3D tmp_cb->ptr();<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 cb_ =3D std::move(tmp_cb);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }=
<br>=C2=A0 }</font></div><div><br></div><div class=3D"subprettyprint"><font=
color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transpar=
ent;">=C2=A0 template <typename U,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 typename V =3D std::enable_if_t<!std::=
is_same<T, U>::value &&<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::is_con=
vertible<U*, T*>::value>><br>=C2=A0 indirect(const indirect<=
U>& p)<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 indirect<U> tmp(p);<b=
r>=C2=A0=C2=A0=C2=A0 ptr_ =3D tmp.ptr_;<br>=C2=A0=C2=A0=C2=A0 cb_ =3D std::=
make_unique<delegating_control_block<T, U>>(std::move(tmp.cb_))=
;<br>=C2=A0 }</font></div><div><br></div><div class=3D"subprettyprint"><fon=
t color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transpa=
rent;">};</font></div><div><br></div><div class=3D"subprettyprint"><font co=
lor=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transparent=
;">template <typename T, typename... Ts><br>indirect<T> make_in=
direct(Ts&&... ts)<br>{<br>=C2=A0 indirect<T> p;<br>=C2=A0 p.=
cb_ =3D std::make_unique<T>(std::forward<Ts>(ts)...);<br>=C2=A0=
p.ptr_ =3D std::get<0>(p.cb_).get();<br>=C2=A0 return p;<br>}<br>=C2=
=A0</font></div></code></div><div><br></div><div>The above can be compiled,=
though most of=C2=A0the impl=C2=A0is missing.</div><div><br></div><div>Thi=
s makes the base case a special case=C2=A0and is=C2=A0as fast as hand-writt=
en copyable unique_ptr. </div><div>If a converting assign is made (=C2=A0A =
a1 =3D=C2=A0b=C2=A0 where b is=C2=A0class B : A) the subsequent assignments=
(A a2 =3D a1)=C2=A0will still be faster, because they do 1 instead of 2 vi=
rtual calls.</div><div>This virtual function call can probably be eliminate=
d as well (for the base case), but for now I am reusing delegating_control_=
block.</div><div><br></div><div>Currently only make_indirect creates the ba=
se case, all else falls back to pointer_control_block . This can be improve=
d, as well as probably=C2=A0much else.</div><div><br></div><div><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/20f19d5f-697a-4560-b27a-87949bd6c804%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/20f19d5f-697a-4560-b27a-87949bd6c804=
%40isocpp.org</a>.<br />
------=_Part_1945_1233214845.1477511344656--
------=_Part_1944_291284803.1477511344655--
.
Author: mihailnajdenov@gmail.com
Date: Thu, 27 Oct 2016 02:48:24 -0700 (PDT)
Raw View
------=_Part_154_511197079.1477561704998
Content-Type: multipart/alternative;
boundary="----=_Part_155_1996898851.1477561704998"
------=_Part_155_1996898851.1477561704998
Content-Type: text/plain; charset=UTF-8
Here's two other suggestion for a name
*A*
If we categorize std types as simple value types (ints, etc) and object
types (strings, vectors etc), the latter of which require heap allocation.
Then indirect serves similar function as what is known as *boxing* in
managed languages - with it we make a simple value type and make it an
"object type".
Yes, objects in C# and C++ are very different, but still, with it, a normal
value like 5 will behave closer to a string or vector or map - requiring a
deep copy and having empty sate.
So how about calling it just box<> or boxed<>?
An abstract name which represents a package,* a shell* of a normal std
object.
A boxed value will behave like an std "object type", packaging all internal
pointer management and having value semantics.
And the shell, the box can be modified to fit your needs - copier, deleter.
Still, because of type erasure, only the simple function remains visible -
to carry around what's in it and giving you access to use it.
*B*
If we assume int and string are both value types, the difference b/w the
two is the type of copy - shallow vs deep
If I use an int - I use a "shallow copy value".
If we call these "shallow values" for short, how can we make a "deep
value"? Well, indirect<> does that!
So how about we call it deep_value<> then?
This name reminds us, we are dealing with a value-semantics object, which
also does deep copy hence heap allocation.
If you use it like deep_value(5) you know the result is still a value-type,
like 5 is, but it will be heap allocated (requiring deep copy)
If you use it like deep_value(ptr) you will know, the result *will become*
a value object and the copies will be deep
For completeness, here are the other names I suggested so far - deep_ptr<>,
deep_copy_ptr<>, remote<>
--
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/d0b2fd4b-eae0-48f0-9290-e7b5307d54ed%40isocpp.org.
------=_Part_155_1996898851.1477561704998
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Here's=C2=A0two other=C2=A0suggestion for a name<=
/div><div><br></div><div><div><b>A</b></div><div><br></div><div>If we categ=
orize std types as simple value types (ints, etc)=C2=A0and object types (st=
rings, vectors etc), the latter of which require heap allocation. </div><di=
v><br></div><div>Then indirect serves similar function as what is known as =
<i>boxing</i> in managed languages -=C2=A0with it we make a simple value ty=
pe and make it an "object type".</div><div>Yes, objects in C# and=
C++ are very different, but still, with it, a normal value like 5 will beh=
ave closer to a string or vector or map -=C2=A0requiring a deep copy and ha=
ving empty sate.</div><div><br></div><div>So how about calling it just box&=
lt;> or boxed<>? </div><div>An abstract name which represents a pa=
ckage,<i> a shell</i> of a normal=C2=A0std object. </div><div>A boxed value=
will behave like an std=C2=A0"object type", packaging all intern=
al pointer management and having value semantics. </div><div><br></div><div=
>And the shell, the box can be modified to fit your needs - copier, deleter=
.. </div><div>Still, because of type erasure, only the simple function remai=
ns visible=C2=A0- to carry around what's in it and giving you access to=
use it.</div></div><div><br></div><div><b>B</b></div><div><br></div><div>I=
f we assume int and string are both value types, the difference b/w the two=
is the type of copy - shallow vs deep</div><div><br></div><div>If I use an=
int=C2=A0-=C2=A0I use a "shallow copy=C2=A0value".</div><div><br=
></div><div>If we call these "shallow values" for short, how can=
=C2=A0we make a "deep value"? Well, indirect<> does that!</=
div><div><br></div><div>So how about we call it deep_value<> then? </=
div><div><br></div><div>This name reminds us, we are dealing with a value-s=
emantics object, which also does deep copy hence heap allocation.</div><div=
><br></div><div>If you use it like deep_value(5) you know the result is sti=
ll a value-type, like 5 is, but it will be heap allocated (requiring deep c=
opy)</div><div>If you use it like deep_value(ptr) you will know, the result=
<i>will become</i> a value object and the copies will be deep</div><div><b=
r></div><div><br></div><div>For completeness, here are the other names I su=
ggested so far - deep_ptr<>, deep_copy_ptr<>, remote<>=C2=
=A0</div><div><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/d0b2fd4b-eae0-48f0-9290-e7b5307d54ed%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d0b2fd4b-eae0-48f0-9290-e7b5307d54ed=
%40isocpp.org</a>.<br />
------=_Part_155_1996898851.1477561704998--
------=_Part_154_511197079.1477561704998--
.
Author: joseph.thomson@gmail.com
Date: Thu, 27 Oct 2016 04:12:17 -0700 (PDT)
Raw View
------=_Part_97_1938064776.1477566737760
Content-Type: multipart/alternative;
boundary="----=_Part_98_320720925.1477566737760"
------=_Part_98_320720925.1477566737760
Content-Type: text/plain; charset=UTF-8
On Wednesday, 26 October 2016 22:48:43 UTC+8, Jonathan Coe wrote:
>
> On 26 October 2016 at 15:30, Ville Voutilainen <ville.vo...@gmail.com
> <javascript:>> wrote:
>
>> On 26 October 2016 at 17:19, Jonathan Coe <jb...@me.com <javascript:>>
>> wrote:
>> > True, for shared_ptr it's a logical rather than implementation
>> restriction.
>> > If we can see how to implement `release` for `indirect` (and keep the
>> > combined allocation) then I see no reason not to add it.
>>
>> I don't see how that could be achieved. The combined object that holds
>> both the deleter
>> and the object inside it would need to be exposed, and that's an
>> implementation-internal
>> type. Ripping apart the pointer and the deleter once they have been
>> combined is not possible.
>>
>>
> That was my impression too.
>
I'm interested to know, what is the aim of this proposal? Is it to provide
a deep copying smart pointer, or to provide a polymorphic value-like
wrapper? I understand you started with a smart pointer design, but made
some adjustments towards a supposedly more value-like design based on the
comments of LEWG. What were their concerns? Why did they not like the idea
of a smart pointer that performs deep copying? You know my concerns about
the design. At the moment it just feels like a stunted deep copying smart
pointer with a confusing name.
Also, a couple of comments about the proposal:
- The postcondition of indirect() should be book(*this) == false
- default_deleter is actually called default_delete; I guess therefore
default_copier should be called default_copy.
--
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/74bd37b5-2b57-4f43-b38c-6f1853bb19c6%40isocpp.org.
------=_Part_98_320720925.1477566737760
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, 26 October 2016 22:48:43 UTC+8, Jona=
than Coe 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"lt=
r">On 26 October 2016 at 15:30, Ville Voutilainen <span dir=3D"ltr"><<a =
href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"F594Hh55AQA=
J" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';return=
true;" onclick=3D"this.href=3D'javascript:';return true;">ville.vo=
....@gmail.com</a>></span> wrote:<br><div><div class=3D"gmail_quote"><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #c=
cc solid;padding-left:1ex"><span>On 26 October 2016 at 17:19, Jonathan Coe =
<<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"F594=
Hh55AQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:'=
;return true;" onclick=3D"this.href=3D'javascript:';return true;">j=
b...@me.com</a>> wrote:<br>
> True, for shared_ptr it's a logical rather than implementation res=
triction.<br>
> If we can see how to implement `release` for `indirect` (and keep the<=
br>
> combined allocation) then I see no reason not to add it.<br>
<br>
</span>I don't see how that could be achieved. The combined object that=
holds<br>
both the deleter<br>
and the object inside it would need to be exposed, and that's an<br>
implementation-internal<br>
type. Ripping apart the pointer and the deleter once they have been<br>
combined is not possible.<br>
<span><br></span></blockquote><div><br></div><div>That was my impression to=
o.</div></div></div></div></blockquote><div><br>I'm interested to know,=
what is the aim of this proposal? Is it to provide a deep copying smart po=
inter, or to provide a polymorphic value-like wrapper? I understand you sta=
rted with a smart pointer design, but made some adjustments towards a suppo=
sedly more value-like design based on the comments of LEWG. What were their=
concerns? Why did they not like the idea of a smart pointer that performs =
deep copying?=C2=A0 You know my concerns about the design. At the moment it=
just feels like a stunted deep copying smart pointer with a confusing name=
..<br><br>Also, a couple of comments about the proposal:<br><ul><li>The post=
condition of indirect() should be book(*this) =3D=3D false</li><li>default_=
deleter is actually called default_delete; I guess therefore default_copier=
should be called default_copy.<br></li></ul></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/74bd37b5-2b57-4f43-b38c-6f1853bb19c6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/74bd37b5-2b57-4f43-b38c-6f1853bb19c6=
%40isocpp.org</a>.<br />
------=_Part_98_320720925.1477566737760--
------=_Part_97_1938064776.1477566737760--
.
Author: joseph.thomson@gmail.com
Date: Thu, 27 Oct 2016 10:01:25 -0700 (PDT)
Raw View
------=_Part_843_1563912261.1477587686047
Content-Type: multipart/alternative;
boundary="----=_Part_844_415813299.1477587686047"
------=_Part_844_415813299.1477587686047
Content-Type: text/plain; charset=UTF-8
>
> Also, a couple of comments about the proposal:
>
> - The postcondition of indirect() should be book(*this) == false
> - default_deleter is actually called default_delete; I guess therefore
> default_copier should be called default_copy.
>
> Oh yeah, and I forgot, probably more significantly, this is not valid,
despite the fact that a copy is being made:
indirect<foo> i = indirect<foo const>();
This could be fixed by requiring that T is a base of U, rather than that U*
to convertible to T*, in the copy constructor and assignment operator.
--
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/ffb81af9-0c5f-40fd-88e6-b062d80c1e15%40isocpp.org.
------=_Part_844_415813299.1477587686047
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><div>Also, a couple of comments about the proposal:<br><ul><li>The post=
condition of indirect() should be book(*this) =3D=3D false</li><li>default_=
deleter is actually called default_delete; I guess therefore default_copier=
should be called default_copy.<br></li></ul></div></div></blockquote><div>=
Oh yeah, and I forgot, probably more significantly, this is not valid, desp=
ite the fact that a copy is being made:<br><br><div style=3D"background-col=
or: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: sol=
id; border-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><c=
ode class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">indirect</span><span style=3D"color:=
#080;" class=3D"styled-by-prettify"><foo></span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> i </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> indirect</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">foo </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">const</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">>();</span></div></code></div><br>This could be fixed by requirin=
g that <span style=3D"font-family: courier new,monospace;">T</span> is a ba=
se of <span style=3D"font-family: courier new,monospace;">U</span>, rather =
than that <span style=3D"font-family: courier new,monospace;">U*</span> to =
convertible to <span style=3D"font-family: courier new,monospace;">T*</span=
>, in the copy constructor and assignment operator.<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/ffb81af9-0c5f-40fd-88e6-b062d80c1e15%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ffb81af9-0c5f-40fd-88e6-b062d80c1e15=
%40isocpp.org</a>.<br />
------=_Part_844_415813299.1477587686047--
------=_Part_843_1563912261.1477587686047--
.
Author: mihailnajdenov@gmail.com
Date: Fri, 28 Oct 2016 09:49:38 -0700 (PDT)
Raw View
------=_Part_651_565234990.1477673378891
Content-Type: multipart/alternative;
boundary="----=_Part_652_1857565239.1477673378891"
------=_Part_652_1857565239.1477673378891
Content-Type: text/plain; charset=UTF-8
On Wednesday, October 26, 2016 at 5:48:43 PM UTC+3, Jonathan Coe wrote:
>
> On 26 October 2016 at 15:30, Ville Voutilainen <ville.vo...@gmail.com
> <javascript:>> wrote:
>
>> On 26 October 2016 at 17:19, Jonathan Coe <jb...@me.com <javascript:>>
>> wrote:
>> ...
>>
>> I don't see how that could be achieved. The combined object that holds
>> both the deleter
>> and the object inside it would need to be exposed, and that's an
>> implementation-internal
>> type. Ripping apart the pointer and the deleter once they have been
>> combined is not possible.
>>
>>
> That was my impression too.
>
Here is striped-down version of the possible solution I was suggesting - to
remove "direct_control_block" and store the unique_ptr directly in the class
This case will be valid and well behaved until a converting assignment is
made. At that point we move the unique_ptr into a pointer_control_block and
continue as usual
http://melpon.org/wandbox/permlink/PPC3kSC5lZqMcXwi
I think this makes it possible to have both release(), and no extra
allocations, because, for the base case, we don't use a control block.
The user will pay extra only if he/she uses extra functionality (virtual
copy and/or type erasure).
Please, comment.
--
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/0dddba42-1ecf-4de9-910d-0a42d11cb0ea%40isocpp.org.
------=_Part_652_1857565239.1477673378891
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, October 26, 2016 at 5:48:43 PM UTC+3=
, Jonathan Coe wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">On 26 October 2016 at 15:30, Ville Voutilainen <span dir=3D"ltr">&=
lt;<a onmousedown=3D"this.href=3D'javascript:';return true;" onclic=
k=3D"this.href=3D'javascript:';return true;" href=3D"javascript:" t=
arget=3D"_blank" rel=3D"nofollow" gdf-obfuscated-mailto=3D"F594Hh55AQAJ">vi=
lle.vo...@gmail.com</a>></span> wrote:<br><div><div class=3D"gmail_quote=
"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex"><span>On 26 October 2016 at 17:19, Jonatha=
n Coe <<a onmousedown=3D"this.href=3D'javascript:';return true;"=
onclick=3D"this.href=3D'javascript:';return true;" href=3D"javascr=
ipt:" target=3D"_blank" rel=3D"nofollow" gdf-obfuscated-mailto=3D"F594Hh55A=
QAJ">jb...@me.com</a>> wrote:<br>
....<br>
<br>
</span>I don't see how that could be achieved. The combined object that=
holds<br>
both the deleter<br>
and the object inside it would need to be exposed, and that's an<br>
implementation-internal<br>
type. Ripping apart the pointer and the deleter once they have been<br>
combined is not possible.<br>
<span><br></span></blockquote><div><br></div><div>That was my impression to=
o.</div></div></div></div></blockquote><div><br></div><div>Here is=C2=A0str=
iped-down version of the possible solution I was suggesting - to remove &qu=
ot;direct_control_block" and store the unique_ptr directly in the clas=
s</div><div><br></div><div>This case will be valid and well behaved until a=
converting assignment is made. At that point we move the unique_ptr into a=
pointer_control_block and continue as usual</div><div><br></div><div><br><=
/div><div>http://melpon.org/wandbox/permlink/PPC3kSC5lZqMcXwi</div><div><br=
></div><div><br></div><div>I think this makes it possible to have both rele=
ase(), and no extra allocations, because, for the base case, we don't u=
se a control block.</div><div><br></div><div>The user will pay extra only i=
f he/she uses extra functionality (virtual copy and/or type erasure). </div=
><div><br></div><div>Please, comment. </div><div><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/0dddba42-1ecf-4de9-910d-0a42d11cb0ea%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0dddba42-1ecf-4de9-910d-0a42d11cb0ea=
%40isocpp.org</a>.<br />
------=_Part_652_1857565239.1477673378891--
------=_Part_651_565234990.1477673378891--
.
Author: Jonathan Coe <jonathanbcoe@gmail.com>
Date: Fri, 28 Oct 2016 20:28:46 +0100
Raw View
--Apple-Mail-1B85A8A6-ECAD-4BDD-90A7-08F8072EC579
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
> On 28 Oct 2016, at 17:49, mihailnajdenov@gmail.com wrote:
>=20
>=20
>=20
>> On Wednesday, October 26, 2016 at 5:48:43 PM UTC+3, Jonathan Coe wrote:
>>> On 26 October 2016 at 15:30, Ville Voutilainen <ville.vo...@gmail.com> =
wrote:
>>> On 26 October 2016 at 17:19, Jonathan Coe <jb...@me.com> wrote:
>>> ...
>>>=20
>>> I don't see how that could be achieved. The combined object that holds
>>> both the deleter
>>> and the object inside it would need to be exposed, and that's an
>>> implementation-internal
>>> type. Ripping apart the pointer and the deleter once they have been
>>> combined is not possible.
>>>=20
>>=20
>> That was my impression too.
>=20
> Here is striped-down version of the possible solution I was suggesting - =
to remove "direct_control_block" and store the unique_ptr directly in the c=
lass
>=20
> This case will be valid and well behaved until a converting assignment is=
made. At that point we move the unique_ptr into a pointer_control_block an=
d continue as usual
>=20
>=20
> http://melpon.org/wandbox/permlink/PPC3kSC5lZqMcXwi
>=20
>=20
> I think this makes it possible to have both release(), and no extra alloc=
ations, because, for the base case, we don't use a control block.
>=20
> The user will pay extra only if he/she uses extra functionality (virtual =
copy and/or type erasure).
>=20
> Please, comment.
>=20
This looks awesome.
Depending on the advice from LEWG regarding custom deleters and copiers thi=
s may or may not be possible. If make_indirect needs to take a custom delet=
ers and copier (currently it does not) then your optimisation is ruled out.=
As things stand, it works and enables release().
Thanks for taking the time to put this together.
> --=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=
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/isoc=
pp.org/d/msgid/std-proposals/0dddba42-1ecf-4de9-910d-0a42d11cb0ea%40isocpp.=
org.
--=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/2842F376-2E08-45E5-B8DD-47ED39D4783D%40gmail.com=
..
--Apple-Mail-1B85A8A6-ECAD-4BDD-90A7-08F8072EC579
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=
=3Dutf-8"></head><body dir=3D"auto"><div></div><div><br></div><div><br>On 2=
8 Oct 2016, at 17:49, <a href=3D"mailto:mihailnajdenov@gmail.com">mihailnaj=
denov@gmail.com</a> wrote:<br><br></div><blockquote type=3D"cite"><div><div=
dir=3D"ltr"><br><br>On Wednesday, October 26, 2016 at 5:48:43 PM UTC+3, Jo=
nathan Coe wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">On 26 October 2016 at 15:30, Ville Voutilainen <span dir=3D"ltr"><<a=
onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.hre=
f=3D'javascript:';return true;" href=3D"javascript:" target=3D"_blank" rel=
=3D"nofollow" gdf-obfuscated-mailto=3D"F594Hh55AQAJ">ville.vo...@gmail.com<=
/a>></span> wrote:<br><div><div class=3D"gmail_quote"><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><span>On 26 October 2016 at 17:19, Jonathan Coe <<a onmous=
edown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'ja=
vascript:';return true;" href=3D"javascript:" target=3D"_blank" rel=3D"nofo=
llow" gdf-obfuscated-mailto=3D"F594Hh55AQAJ">jb...@me.com</a>> wrote:<br=
>
....<br>
<br>
</span>I don't see how that could be achieved. The combined object that hol=
ds<br>
both the deleter<br>
and the object inside it would need to be exposed, and that's an<br>
implementation-internal<br>
type. Ripping apart the pointer and the deleter once they have been<br>
combined is not possible.<br>
<span><br></span></blockquote><div><br></div><div>That was my impression to=
o.</div></div></div></div></blockquote><div><br></div><div>Here is str=
iped-down version of the possible solution I was suggesting - to remove "di=
rect_control_block" and store the unique_ptr directly in the class</div><di=
v><br></div><div>This case will be valid and well behaved until a convertin=
g assignment is made. At that point we move the unique_ptr into a pointer_c=
ontrol_block and continue as usual</div><div><br></div><div><br></div><div>=
<a href=3D"http://melpon.org/wandbox/permlink/PPC3kSC5lZqMcXwi">http://melp=
on.org/wandbox/permlink/PPC3kSC5lZqMcXwi</a></div><div><br></div><div><br><=
/div><div>I think this makes it possible to have both release(), and no ext=
ra allocations, because, for the base case, we don't use a control block.</=
div><div><br></div><div>The user will pay extra only if he/she uses extra f=
unctionality (virtual copy and/or type erasure). </div><div><br></div><div>=
Please, comment. </div><div><br></div></div></div></blockquote><div><br></d=
iv>This looks awesome.<div><br></div><div>Depending on the advice from LEWG=
regarding custom deleters and copiers this may or may not be possible. If =
make_indirect needs to take a custom deleters and copier (currently it does=
not) then your optimisation is ruled out. As things stand, it works and en=
ables release().</div><div><br></div><div>Thanks for taking the time to put=
this together.<br><blockquote type=3D"cite"><div><div dir=3D"ltr">
</div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups "=
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/0dddba42-1ecf-4de9-910d-0a42d11cb0ea%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.goo=
gle.com/a/isocpp.org/d/msgid/std-proposals/0dddba42-1ecf-4de9-910d-0a42d11c=
b0ea%40isocpp.org</a>.<br>
</div></blockquote></div></body></html>
<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/2842F376-2E08-45E5-B8DD-47ED39D4783D%=
40gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/2842F376-2E08-45E5-B8DD-47ED39D4783D%=
40gmail.com</a>.<br />
--Apple-Mail-1B85A8A6-ECAD-4BDD-90A7-08F8072EC579--
.
Author: mihailnajdenov@gmail.com
Date: Fri, 28 Oct 2016 13:40:43 -0700 (PDT)
Raw View
------=_Part_1254_350240602.1477687243253
Content-Type: multipart/alternative;
boundary="----=_Part_1255_1620116772.1477687243253"
------=_Part_1255_1620116772.1477687243253
Content-Type: text/plain; charset=UTF-8
On Friday, October 28, 2016 at 10:28:50 PM UTC+3, Jonathan Coe wrote:
....
>
> This looks awesome.
>
> Depending on the advice from LEWG regarding custom deleters and copiers
> this may or may not be possible. If make_indirect needs to take a custom
> deleters and copier (currently it does not) then your optimisation is ruled
> out. As things stand, it works and enables release().
>
> Thanks for taking the time to put this together.
>
Further notes.
We can define the base case to be unique_ptr<T, default_deleter<T>> and use
default_copier<T> on copy,
this way we can detect, the user tried to use default_ it in the ctor (or
in make_).
If all items passed are the defaults, and T == U, then it is safe to create
a base case. Later, if *any* of those requirements changes - we switch to
control_block case.
std::variant <
std::unique_ptr<T, default_deleter<T>>
...
> cb_;
....
indirect(const indirect& p){
....
auto tmp_cb = std::make_unique<T>(default_copier<T>{}(*std::get<0>(p.cb_)));
....
}
template<...>
indirect(U* u, C copier = C{}, D deleter = D{})
{
...
if constexpr(typeid(T) == typeid(U)
&& typeid(C) == typeid(default_copier<T>)
&& typeid(D) == typeid(default_deleter<T>))
{
cb_ = std::unique_ptr<T, D>(u);
}
else
{
cb_ = std::make_unique<pointer_control_block<T, U, C, D>>(u, std::move(copier),
std::move(deleter));
}
ptr_ = u;
}
Something like that.
I think we can always know if we are constructed in a such a way that we
need control_block or not.
If not - then the base case (whatever it is) will be valid until we are
reassign with a different type.
--
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/ab40a832-f405-4c89-91d3-3013739ecd52%40isocpp.org.
------=_Part_1255_1620116772.1477687243253
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><br>On Friday, October 28, 2016 at 10:28:50 PM UTC+3,=
Jonathan Coe wrote:</div><div>...<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddin=
g-left: 1ex;"><div dir=3D"auto"><div><br></div>This looks awesome.<div><br>=
</div><div>Depending on the advice from LEWG regarding custom deleters and =
copiers this may or may not be possible. If make_indirect needs to take a c=
ustom deleters and copier (currently it does not) then your optimisation is=
ruled out. As things stand, it works and enables release().</div><div><br>=
</div><div>Thanks for taking the time to put this together.<br></div></div>=
</blockquote><div><br></div><div>Further notes. </div><div>We can define th=
e base case to be unique_ptr<T, default_deleter<T>> and use def=
ault_copier<T> on copy,</div><div>this way we can detect, the user tr=
ied to use default_=C2=A0 it in the ctor (or in make_).</div><div><br></div=
><div>If all items passed=C2=A0are the=C2=A0defaults, and T =3D=3D U, then =
it is safe to create a base case. Later, if <i>any</i> of those requirement=
s=C2=A0changes=C2=A0=C2=A0- we switch to control_block case.</div><div><br>=
</div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 1=
87); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code cl=
ass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D" color:#c0=
c0c0;"><span class=3D"styled-by-prettify" style=3D"color: #000;">=C2=A0</sp=
an></span><span class=3D"styled-by-prettify" style=3D"color: #000;">std</sp=
an><span style=3D" color:#000000;"><span class=3D"styled-by-prettify" style=
=3D"color: #660;">::</span></span><span class=3D"styled-by-prettify" style=
=3D"color: #000;">variant</span><span style=3D" color:#c0c0c0;"><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> </span></span><span style=
=3D" color:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #66=
0;"><</span></span><span class=3D"styled-by-prettify" style=3D"color: #0=
00;"><br></span><pre style=3D" margin-top:0px; margin-bottom:0px; margin-le=
ft:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=
=3D" color:#c0c0c0;"><span class=3D"styled-by-prettify" style=3D"color: #00=
0;">=C2=A0 =C2=A0 </span></span><span class=3D"styled-by-prettify" style=3D=
"color: #000;">std</span><span style=3D" color:#000000;"><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">::</span></span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;">unique_ptr</span><span style=3D" col=
or:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #660;"><=
</span></span><span class=3D"styled-by-prettify" style=3D"color: #000;">T</=
span><span class=3D"styled-by-prettify" style=3D"color: #660;">,</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span style=
=3D" color:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #00=
0;">default_deleter</span><span class=3D"styled-by-prettify" style=3D"color=
: #660;"><</span><span class=3D"styled-by-prettify" style=3D"color: #000=
;">T</span><span class=3D"styled-by-prettify" style=3D"color: #660;">>&g=
t;</span></span><span class=3D"styled-by-prettify" style=3D"color: #000;"><=
br></span></pre><pre style=3D" margin-top:0px; margin-bottom:0px; margin-le=
ft:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=
=3D" color:#c0c0c0;"><span class=3D"styled-by-prettify" style=3D"color: #00=
0;">=C2=A0 =C2=A0</span></span><span style=3D" color:#000000;"><span class=
=3D"styled-by-prettify" style=3D"color: #660;">...</span></span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"><br></span></pre><pre style=
=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; =
-qt-block-indent:0; text-indent:0px;"><span style=3D" color:#c0c0c0;"><span=
class=3D"styled-by-prettify" style=3D"color: #000;">=C2=A0 </span></span><=
span style=3D" color:#000000;"><span class=3D"styled-by-prettify" style=3D"=
color: #660;">></span></span><span style=3D" color:#c0c0c0;"><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> </span></span><span style=
=3D" color:#800000;"><span class=3D"styled-by-prettify" style=3D"color: #00=
0;">cb_</span></span><span style=3D" color:#000000;"><span class=3D"styled-=
by-prettify" style=3D"color: #660;">;</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" st=
yle=3D"color: #660;">...</span><span class=3D"styled-by-prettify" style=3D"=
color: #000;"><br><br></span><span style=3D" color:#00aaff;"><span class=3D=
"styled-by-prettify" style=3D"color: #000;">indirect</span></span><span sty=
le=3D" color:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #=
660;">(</span></span><span style=3D" color:#0000ff;"><span class=3D"styled-=
by-prettify" style=3D"color: #008;">const</span></span><span style=3D" colo=
r:#c0c0c0;"><span class=3D"styled-by-prettify" style=3D"color: #000;"> </sp=
an></span><span style=3D" color:#00aaff;"><span class=3D"styled-by-prettify=
" style=3D"color: #000;">indirect</span></span><span style=3D" color:#00000=
0;"><span class=3D"styled-by-prettify" style=3D"color: #660;">&</span><=
/span><span style=3D" color:#c0c0c0;"><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;"> </span></span><span style=3D" color:#000000;"><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;">p</span></span><span sty=
le=3D" color:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #=
660;">){</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><b=
r></span><span class=3D"styled-by-prettify" style=3D"color: #660;">...</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><spa=
n style=3D" color:#0000ff;"><span class=3D"styled-by-prettify" style=3D"col=
or: #008;">auto</span></span><span style=3D" color:#c0c0c0;"><span class=3D=
"styled-by-prettify" style=3D"color: #000;"> </span></span><span style=3D" =
color:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #000;">t=
mp_cb</span></span><span style=3D" color:#c0c0c0;"><span class=3D"styled-by=
-prettify" style=3D"color: #000;"> </span></span><span style=3D" color:#000=
000;"><span class=3D"styled-by-prettify" style=3D"color: #660;">=3D</span><=
/span><span style=3D" color:#c0c0c0;"><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;"> </span></span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;">std</span><span style=3D" color:#000000;"><span class=3D=
"styled-by-prettify" style=3D"color: #660;">::</span></span><span class=3D"=
styled-by-prettify" style=3D"color: #000;">make_unique</span><span style=3D=
" color:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #660;"=
><</span></span><span class=3D"styled-by-prettify" style=3D"color: #000;=
">T</span><span style=3D" color:#000000;"><span class=3D"styled-by-prettify=
" style=3D"color: #660;">>(</span><span style=3D" color:#000000;"><span =
class=3D"styled-by-prettify" style=3D"color: #000;">default_copier</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #660;"><</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: #000;">T</span><span class=3D"st=
yled-by-prettify" style=3D"color: #660;">>{}(</span></span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">*</span></span><span class=
=3D"styled-by-prettify" style=3D"color: #000;">std</span><span style=3D" co=
lor:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #660;">::<=
/span></span><span class=3D"styled-by-prettify" style=3D"color: #008;">get<=
/span><span style=3D" color:#000000;"><span class=3D"styled-by-prettify" st=
yle=3D"color: #660;"><</span></span><span style=3D" color:#ff0000;"><spa=
n class=3D"styled-by-prettify" style=3D"color: #066;">0</span></span><span =
style=3D" color:#000000;"><span class=3D"styled-by-prettify" style=3D"color=
: #660;">>(</span></span><span style=3D" color:#000000;"><span class=3D"=
styled-by-prettify" style=3D"color: #000;">p</span></span><span style=3D" c=
olor:#000000;"><span class=3D"styled-by-prettify" style=3D"color: #660;">.<=
/span></span><span style=3D" color:#800000;"><span class=3D"styled-by-prett=
ify" style=3D"color: #000;">cb_</span></span><span style=3D" color:#000000;=
"><span class=3D"styled-by-prettify" style=3D"color: #660;">)));</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">...</span></span><b><i><u><=
sub><sup><strike><span class=3D"styled-by-prettify" style=3D"color: #000;">=
<br></span></strike></sup></sub></u></i></b><span class=3D"styled-by-pretti=
fy" style=3D"color: #660;">}</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"><br><br></span><span class=3D"styled-by-prettify" style=
=3D"color: #008;">template</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;"><...></span><font color=3D"rgb(102,102,0)"><span cl=
ass=3D"styled-by-prettify" style=3D"color: #000;"> =C2=A0<br>indirect</span=
><span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: #000;">U</span><span class=3D"st=
yled-by-prettify" style=3D"color: #660;">*</span><span class=3D"styled-by-p=
rettify" style=3D"color: #000;"> u</span><span class=3D"styled-by-prettify"=
style=3D"color: #660;">,</span><span class=3D"styled-by-prettify" style=3D=
"color: #000;"> C copier </span><span class=3D"styled-by-prettify" style=3D=
"color: #660;">=3D</span><span class=3D"styled-by-prettify" style=3D"color:=
#000;"> C</span><span class=3D"styled-by-prettify" style=3D"color: #660;">=
{},</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> D dele=
ter </span><span class=3D"styled-by-prettify" style=3D"color: #660;">=3D</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;"> D</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #660;">{})</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">{</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"><br></span></font></span></span><span=
style=3D" color:#000000;"><span style=3D" color:#000000;"><font color=3D"r=
gb(102,102,0)"><span class=3D"styled-by-prettify" style=3D"color: #000;">=
=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #66=
0;">...</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br=
>=C2=A0 =C2=A0 <br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" =
style=3D"color: #008;">if</span><span class=3D"styled-by-prettify" style=3D=
"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color: #=
008;">constexpr</span><span class=3D"styled-by-prettify" style=3D"color: #6=
60;">(</span><span class=3D"styled-by-prettify" style=3D"color: #008;">type=
id</span><span class=3D"styled-by-prettify" style=3D"color: #660;">(</span>=
<span class=3D"styled-by-prettify" style=3D"color: #000;">T</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #660;">)</span><span class=3D"sty=
led-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-pr=
ettify" style=3D"color: #660;">=3D=3D</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=
=3D"color: #008;">typeid</span><span class=3D"styled-by-prettify" style=3D"=
color: #660;">(</span><span class=3D"styled-by-prettify" style=3D"color: #0=
00;">U</span><span class=3D"styled-by-prettify" style=3D"color: #660;">)</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;"> <br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">&&</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color=
: #008;">typeid</span><span class=3D"styled-by-prettify" style=3D"color: #6=
60;">(</span><span class=3D"styled-by-prettify" style=3D"color: #000;">C</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #660;">)</span><span=
class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D=
"styled-by-prettify" style=3D"color: #660;">=3D=3D</span><span class=3D"sty=
led-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-pr=
ettify" style=3D"color: #008;">typeid</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;">default_copier</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #660;"><</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;">T</span><span class=3D"styled-by-prettify" style=3D"color=
: #660;">>)</span><span class=3D"styled-by-prettify" style=3D"color: #00=
0;"> <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span class=3D"styled-by=
-prettify" style=3D"color: #660;">&&</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify=
" style=3D"color: #008;">typeid</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #660;">(</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;">D</span><span class=3D"styled-by-prettify" style=3D"color: #660=
;">)</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </spa=
n><span class=3D"styled-by-prettify" style=3D"color: #660;">=3D=3D</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">typeid</span><span class=3D"=
styled-by-prettify" style=3D"color: #660;">(</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;">default_deleter</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #660;"><</span><span class=3D"styled-by-=
prettify" style=3D"color: #000;">T</span><span class=3D"styled-by-prettify"=
style=3D"color: #660;">>))</span><span class=3D"styled-by-prettify" sty=
le=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">{</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;"><br>=C2=A0 =C2=A0 =C2=A0 cb_ </span><span class=3D"style=
d-by-prettify" style=3D"color: #660;">=3D</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #000;"> std</span><span class=3D"styled-by-prettify=
" style=3D"color: #660;">::</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;">unique_ptr</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;"><</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;">T</span><span class=3D"styled-by-prettify" style=3D"color: #660=
;">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> D</sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;">>(</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;">u</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">);</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;"> <br>=C2=A0 =C2=A0 </span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">}</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">else</span><span class=3D"st=
yled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #660;">{</span><span class=3D"sty=
led-by-prettify" style=3D"color: #000;"><br></span></font></span></span></p=
re><pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margi=
n-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=3D" color:#0=
00000;"><span style=3D" color:#000000;"><font color=3D"rgb(102,102,0)"><spa=
n class=3D"styled-by-prettify" style=3D"color: #000;">=C2=A0 =C2=A0 =C2=A0 =
cb_ </span><span class=3D"styled-by-prettify" style=3D"color: #660;">=3D</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;"> std</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #660;">::</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #000;">make_unique</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #660;"><</span><span class=3D"=
styled-by-prettify" style=3D"color: #000;">pointer_control_block</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #660;"><</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #000;">T</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #660;">,</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #000;"> U</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #660;">,</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #000;"> C</span><span class=3D"styled-by-prettify" style=3D"color: #6=
60;">,</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> D</=
span><span class=3D"styled-by-prettify" style=3D"color: #660;">>>(</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;">u</span><span=
class=3D"styled-by-prettify" style=3D"color: #660;">,</span><span class=3D=
"styled-by-prettify" style=3D"color: #000;"> std</span><span class=3D"style=
d-by-prettify" style=3D"color: #660;">::</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #000;">move</span><span class=3D"styled-by-prettify"=
style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" style=3D=
"color: #000;">copier</span><span class=3D"styled-by-prettify" style=3D"col=
or: #660;">),</span><span class=3D"styled-by-prettify" style=3D"color: #000=
;"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0std</span><span class=3D"styled-by-prettify" style=3D"color: #660;">::</=
span><span class=3D"styled-by-prettify" style=3D"color: #000;">move</span><=
span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #000;">deleter</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">));</span><span class=3D"sty=
led-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">}</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 ptr_ </span><span =
class=3D"styled-by-prettify" style=3D"color: #660;">=3D</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> u</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #660;">;</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #000;"><br>=C2=A0 </span><span class=3D"styled-by-pr=
ettify" style=3D"color: #660;">}</span></font></span></span><span style=3D"=
color:#000000;"><span style=3D" color:#000000;"><span class=3D"styled-by-p=
rettify" style=3D"color: #000;"><br></span></span></span></pre><span style=
=3D" color:#000000;"><pre style=3D" margin-top:0px; margin-bottom:0px; marg=
in-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span =
class=3D"styled-by-prettify" style=3D"color: #000;"><br></span></pre></span=
><pre style=3D" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-=
right:0px; -qt-block-indent:0; text-indent:0px;"></pre></div></code></div><=
div><b><br></b></div><div>Something like that. </div><div>I think we can=C2=
=A0always know if we are constructed=C2=A0in a such a=C2=A0way that we need=
control_block or not. </div><div>If not - then the base case (whatever it =
is)=C2=A0will be valid until we are reassign with a different type.</div><d=
iv><br></div><div><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/ab40a832-f405-4c89-91d3-3013739ecd52%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ab40a832-f405-4c89-91d3-3013739ecd52=
%40isocpp.org</a>.<br />
------=_Part_1255_1620116772.1477687243253--
------=_Part_1254_350240602.1477687243253--
.
Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Fri, 28 Oct 2016 15:35:40 -0700 (PDT)
Raw View
------=_Part_750_1138258204.1477694140612
Content-Type: multipart/alternative;
boundary="----=_Part_751_1611258010.1477694140613"
------=_Part_751_1611258010.1477694140613
Content-Type: text/plain; charset=UTF-8
An implementation could save the size of the variant's tag by defining that
a null control block pointer means to use the default mechanisms for copy
and destroy. This costs a null test in some methods though.
Den fredag 28 oktober 2016 kl. 22:40:43 UTC+2 skrev mihailn...@gmail.com:
>
>
> On Friday, October 28, 2016 at 10:28:50 PM UTC+3, Jonathan Coe wrote:
> ...
>
>>
>> This looks awesome.
>>
>> Depending on the advice from LEWG regarding custom deleters and copiers
>> this may or may not be possible. If make_indirect needs to take a custom
>> deleters and copier (currently it does not) then your optimisation is ruled
>> out. As things stand, it works and enables release().
>>
>> Thanks for taking the time to put this together.
>>
>
> Further notes.
> We can define the base case to be unique_ptr<T, default_deleter<T>> and
> use default_copier<T> on copy,
> this way we can detect, the user tried to use default_ it in the ctor (or
> in make_).
>
> If all items passed are the defaults, and T == U, then it is safe to
> create a base case. Later, if *any* of those requirements changes - we
> switch to control_block case.
>
> std::variant <
>
> std::unique_ptr<T, default_deleter<T>>
>
> ...
>
> > cb_;
> ...
>
> indirect(const indirect& p){
> ...
> auto tmp_cb = std::make_unique<T>(default_copier<T>{}(*std::get<0>(p.cb_)));
> ...
> }
>
> template<...>
> indirect(U* u, C copier = C{}, D deleter = D{})
> {
> ...
>
> if constexpr(typeid(T) == typeid(U)
> && typeid(C) == typeid(default_copier<T>)
> && typeid(D) == typeid(default_deleter<T>))
> {
> cb_ = std::unique_ptr<T, D>(u);
> }
> else
> {
>
> cb_ = std::make_unique<pointer_control_block<T, U, C, D>>(u, std::move(copier),
> std::move(deleter));
> }
> ptr_ = u;
> }
>
>
>
> Something like that.
> I think we can always know if we are constructed in a such a way that we
> need control_block or not.
> If not - then the base case (whatever it is) will be valid until we are
> reassign with a different type.
>
>
>
--
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/da0dfe4b-a369-4b2d-a449-b1df9ddac018%40isocpp.org.
------=_Part_751_1611258010.1477694140613
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">An implementation could save the size of the variant's=
tag by defining that a null control block pointer means to use the default=
mechanisms for copy and destroy. This costs a null test in some methods th=
ough.<div><br>Den fredag 28 oktober 2016 kl. 22:40:43 UTC+2 skrev mihailn..=
..@gmail.com:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><=
div><br>On Friday, October 28, 2016 at 10:28:50 PM UTC+3, Jonathan Coe wrot=
e:</div><div>...<br></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"auto"><div><br></div>This looks awesome.<div><br></div><div>Depending o=
n the advice from LEWG regarding custom deleters and copiers this may or ma=
y not be possible. If make_indirect needs to take a custom deleters and cop=
ier (currently it does not) then your optimisation is ruled out. As things =
stand, it works and enables release().</div><div><br></div><div>Thanks for =
taking the time to put this together.<br></div></div></blockquote><div><br>=
</div><div>Further notes. </div><div>We can define the base case to be uniq=
ue_ptr<T, default_deleter<T>> and use default_copier<T> o=
n copy,</div><div>this way we can detect, the user tried to use default_=C2=
=A0 it in the ctor (or in make_).</div><div><br></div><div>If all items pas=
sed=C2=A0are the=C2=A0defaults, and T =3D=3D U, then it is safe to create a=
base case. Later, if <i>any</i> of those requirements=C2=A0changes=C2=A0=
=C2=A0- we switch to control_block case.</div><div><br></div><div style=3D"=
border:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb=
(250,250,250)"><code><div><span style=3D"color:#c0c0c0"><span style=3D"colo=
r:#000">=C2=A0</span></span><span style=3D"color:#000">std</span><span styl=
e=3D"color:#000000"><span style=3D"color:#660">::</span></span><span style=
=3D"color:#000">variant</span><span style=3D"color:#c0c0c0"><span style=3D"=
color:#000"> </span></span><span style=3D"color:#000000"><span style=3D"col=
or:#660"><</span></span><span style=3D"color:#000"><br></span><pre style=
=3D"margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-=
indent:0px"><span style=3D"color:#c0c0c0"><span style=3D"color:#000">=C2=A0=
=C2=A0 </span></span><span style=3D"color:#000">std</span><span style=3D"c=
olor:#000000"><span style=3D"color:#660">::</span></span><span style=3D"col=
or:#000">unique_ptr</span><span style=3D"color:#000000"><span style=3D"colo=
r:#660"><</span></span><span style=3D"color:#000">T</span><span style=3D=
"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#000000"><span style=3D"color:#000">default_deleter</span><span style=3D"=
color:#660"><</span><span style=3D"color:#000">T</span><span style=3D"co=
lor:#660">>></span></span><span style=3D"color:#000"><br></span></pre=
><pre style=3D"margin-top:0px;margin-bottom:0px;margin-left:0px;margin-righ=
t:0px;text-indent:0px"><span style=3D"color:#c0c0c0"><span style=3D"color:#=
000">=C2=A0 =C2=A0</span></span><span style=3D"color:#000000"><span style=
=3D"color:#660">...</span></span><span style=3D"color:#000"><br></span></pr=
e><pre style=3D"margin-top:0px;margin-bottom:0px;margin-left:0px;margin-rig=
ht:0px;text-indent:0px"><span style=3D"color:#c0c0c0"><span style=3D"color:=
#000">=C2=A0 </span></span><span style=3D"color:#000000"><span style=3D"col=
or:#660">></span></span><span style=3D"color:#c0c0c0"><span style=3D"col=
or:#000"> </span></span><span style=3D"color:#800000"><span style=3D"color:=
#000">cb_</span></span><span style=3D"color:#000000"><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#66=
0">...</span><span style=3D"color:#000"><br><br></span><span style=3D"color=
:#00aaff"><span style=3D"color:#000">indirect</span></span><span style=3D"c=
olor:#000000"><span style=3D"color:#660">(</span></span><span style=3D"colo=
r:#0000ff"><span style=3D"color:#008">const</span></span><span style=3D"col=
or:#c0c0c0"><span style=3D"color:#000"> </span></span><span style=3D"color:=
#00aaff"><span style=3D"color:#000">indirect</span></span><span style=3D"co=
lor:#000000"><span style=3D"color:#660">&</span></span><span style=3D"c=
olor:#c0c0c0"><span style=3D"color:#000"> </span></span><span style=3D"colo=
r:#000000"><span style=3D"color:#000">p</span></span><span style=3D"color:#=
000000"><span style=3D"color:#660">){</span><span style=3D"color:#000"><br>=
</span><span style=3D"color:#660">...</span><span style=3D"color:#000"><br>=
</span><span style=3D"color:#0000ff"><span style=3D"color:#008">auto</span>=
</span><span style=3D"color:#c0c0c0"><span style=3D"color:#000"> </span></s=
pan><span style=3D"color:#000000"><span style=3D"color:#000">tmp_cb</span><=
/span><span style=3D"color:#c0c0c0"><span style=3D"color:#000"> </span></sp=
an><span style=3D"color:#000000"><span style=3D"color:#660">=3D</span></spa=
n><span style=3D"color:#c0c0c0"><span style=3D"color:#000"> </span></span><=
span style=3D"color:#000">std</span><span style=3D"color:#000000"><span sty=
le=3D"color:#660">::</span></span><span style=3D"color:#000">make_unique</s=
pan><span style=3D"color:#000000"><span style=3D"color:#660"><</span></s=
pan><span style=3D"color:#000">T</span><span style=3D"color:#000000"><span =
style=3D"color:#660">>(</span><span style=3D"color:#000000"><span style=
=3D"color:#000">default_<wbr>copier</span><span style=3D"color:#660"><</=
span><span style=3D"color:#000">T</span><span style=3D"color:#660">>{}(<=
/span></span><span style=3D"color:#660">*</span></span><span style=3D"color=
:#000">std</span><span style=3D"color:#000000"><span style=3D"color:#660">:=
:</span></span><span style=3D"color:#008">get</span><span style=3D"color:#0=
00000"><span style=3D"color:#660"><</span></span><span style=3D"color:#f=
f0000"><span style=3D"color:#066">0</span></span><span style=3D"color:#0000=
00"><span style=3D"color:#660">>(</span></span><span style=3D"color:#000=
000"><span style=3D"color:#000">p</span></span><span style=3D"color:#000000=
"><span style=3D"color:#660">.</span></span><span style=3D"color:#800000"><=
span style=3D"color:#000">cb_</span></span><span style=3D"color:#000000"><s=
pan style=3D"color:#660"><wbr>)));</span><span style=3D"color:#000"><br></s=
pan><span style=3D"color:#660">...</span></span><b><i><u><sub><sup><strike>=
<span style=3D"color:#000"><br></span></strike></sup></sub></u></i></b><spa=
n style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><s=
pan style=3D"color:#008">template</span><span style=3D"color:#660"><...&=
gt;</span><font color=3D"rgb(102,102,0)"><span style=3D"color:#000"> =C2=A0=
<br>indirect</span><span style=3D"color:#660">(</span><span style=3D"color:=
#000">U</span><span style=3D"color:#660">*</span><span style=3D"color:#000"=
> u</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> C =
copier </span><span style=3D"color:#660">=3D</span><span style=3D"color:#00=
0"> C</span><span style=3D"color:#660">{},</span><span style=3D"color:#000"=
> D deleter </span><span style=3D"color:#660">=3D</span><span style=3D"colo=
r:#000"> D</span><span style=3D"color:#660">{})</span><span style=3D"color:=
#000"><br>=C2=A0</span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br></span></font></span></span><span style=3D"color:#000000"><sp=
an style=3D"color:#000000"><font color=3D"rgb(102,102,0)"><span style=3D"co=
lor:#000">=C2=A0 =C2=A0 </span><span style=3D"color:#660">...</span><span s=
tyle=3D"color:#000"><br>=C2=A0 =C2=A0 <br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#008">if</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">constexpr</span><span style=3D"color:#660">(</span><span style=
=3D"color:#008">typeid</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">T</span><span style=3D"color:#660">)</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">=3D=3D</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#008">typeid</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">U</span><span style=3D"color:=
#660">)</span><span style=3D"color:#000"> <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 </span><span style=3D"color:#660">&&</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">typeid</span><span style=3D"co=
lor:#660">(</span><span style=3D"color:#000">C</span><span style=3D"color:#=
660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=
=3D=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#008">=
typeid</span><span style=3D"color:#660">(</span><span style=3D"color:#000">=
default_copier</span><span style=3D"color:#660"><</span><span style=3D"c=
olor:#000">T</span><span style=3D"color:#660">>)</span><span style=3D"co=
lor:#000"> <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"col=
or:#660">&&</span><span style=3D"color:#000"> </span><span style=3D=
"color:#008">typeid</span><span style=3D"color:#660">(</span><span style=3D=
"color:#000">D</span><span style=3D"color:#660">)</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">=3D=3D</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#008">typeid</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">default_deleter</span><span styl=
e=3D"color:#660"><</span><span style=3D"color:#000">T</span><span style=
=3D"color:#660">>))</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 <=
/span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 =C2=A0 cb_ </span><span style=3D"color:#660">=3D</span><span sty=
le=3D"color:#000"> std</span><span style=3D"color:#660">::</span><span styl=
e=3D"color:#000">unique_ptr</span><span style=3D"color:#660"><</span><sp=
an style=3D"color:#000">T</span><span style=3D"color:#660">,</span><span st=
yle=3D"color:#000"> D</span><span style=3D"color:#660">>(</span><span st=
yle=3D"color:#000">u</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"> <br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#008">else</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span =
style=3D"color:#660">{</span><span style=3D"color:#000"><br></span></font><=
/span></span></pre><pre style=3D"margin-top:0px;margin-bottom:0px;margin-le=
ft:0px;margin-right:0px;text-indent:0px"><span style=3D"color:#000000"><spa=
n style=3D"color:#000000"><font color=3D"rgb(102,102,0)"><span style=3D"col=
or:#000">=C2=A0 =C2=A0 =C2=A0 cb_ </span><span style=3D"color:#660">=3D</sp=
an><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</spa=
n><span style=3D"color:#000">make_unique</span><span style=3D"color:#660">&=
lt;</span><span style=3D"color:#000">pointer_<wbr>control_block</span><span=
style=3D"color:#660"><</span><span style=3D"color:#000">T</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> U</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> C</span><span style=3D"=
color:#660">,</span><span style=3D"color:#000"> D</span><span style=3D"colo=
r:#660">>>(</span><span style=3D"color:#000">u</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> std</span><span style=3D"col=
or:#660">::</span><span style=3D"color:#000">move</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">copier</span><span style=3D"colo=
r:#660">),</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0std</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">move</span><span style=3D"color:#660=
">(</span><span style=3D"color:#000">deleter</span><span style=3D"color:#66=
0">));</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 ptr_ =
</span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> u</=
span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=
=A0 </span><span style=3D"color:#660">}</span></font></span></span><span st=
yle=3D"color:#000000"><span style=3D"color:#000000"><span style=3D"color:#0=
00"><br></span></span></span></pre><span style=3D"color:#000000"><pre style=
=3D"margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-=
indent:0px"><span style=3D"color:#000"><br></span></pre></span><pre style=
=3D"margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-=
indent:0px"></pre></div></code></div><div><b><br></b></div><div>Something l=
ike that. </div><div>I think we can=C2=A0always know if we are constructed=
=C2=A0in a such a=C2=A0way that we need control_block or not. </div><div>If=
not - then the base case (whatever it is)=C2=A0will be valid until we are =
reassign with a different type.</div><div><br></div><div><br></div></div></=
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/da0dfe4b-a369-4b2d-a449-b1df9ddac018%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/da0dfe4b-a369-4b2d-a449-b1df9ddac018=
%40isocpp.org</a>.<br />
------=_Part_751_1611258010.1477694140613--
------=_Part_750_1138258204.1477694140612--
.
Author: joseph.thomson@gmail.com
Date: Sat, 29 Oct 2016 01:51:21 -0700 (PDT)
Raw View
------=_Part_1027_1723866445.1477731081513
Content-Type: multipart/alternative;
boundary="----=_Part_1028_2095449904.1477731081514"
------=_Part_1028_2095449904.1477731081514
Content-Type: text/plain; charset=UTF-8
On Saturday, 29 October 2016 03:28:50 UTC+8, Jonathan Coe wrote:
>
>
>
> On 28 Oct 2016, at 17:49, mihailn...@gmail.com <javascript:> wrote:
>
>
>
> On Wednesday, October 26, 2016 at 5:48:43 PM UTC+3, Jonathan Coe wrote:
>>
>> On 26 October 2016 at 15:30, Ville Voutilainen <ville.vo...@gmail.com>
>> wrote:
>>
>>> On 26 October 2016 at 17:19, Jonathan Coe <jb...@me.com> wrote:
>>> ...
>>>
>>> I don't see how that could be achieved. The combined object that holds
>>> both the deleter
>>> and the object inside it would need to be exposed, and that's an
>>> implementation-internal
>>> type. Ripping apart the pointer and the deleter once they have been
>>> combined is not possible.
>>>
>>>
>> That was my impression too.
>>
>
> Here is striped-down version of the possible solution I was suggesting -
> to remove "direct_control_block" and store the unique_ptr directly in the
> class
>
> This case will be valid and well behaved until a converting assignment is
> made. At that point we move the unique_ptr into a pointer_control_block and
> continue as usual
>
>
> http://melpon.org/wandbox/permlink/PPC3kSC5lZqMcXwi
>
>
> I think this makes it possible to have both release(), and no extra
> allocations, because, for the base case, we don't use a control block.
>
> The user will pay extra only if he/she uses extra functionality (virtual
> copy and/or type erasure).
>
> Please, comment.
>
>
> This looks awesome.
>
> Depending on the advice from LEWG regarding custom deleters and copiers
> this may or may not be possible. If make_indirect needs to take a custom
> deleters and copier (currently it does not) then your optimisation is ruled
> out. As things stand, it works and enables release().
>
> Thanks for taking the time to put this together.
>
If you require the copier and deleter to be function pointers, then you can
implement type erasure without virtual dispatch. I don't think there is
precident for this in the standard library though.
#include <memory>
template <typename T, T* (*)(T*)>
struct copy_f {};
template <typename T, T* (*C)(T*)>
void* type_erased_copy(void* v)
{
return C(static_cast<T*>(v));
}
template <typename T>
T* default_copy(T* t)
{
return new T(*t);
}
template <typename T>
class dcp
{
template <typename U, U* (*)(U*), typename... Ts>
friend dcp<U> make_dcp(Ts&&...);
private:
std::unique_ptr<T> t;
void* (*c)(void*) = nullptr;
template <typename U, U* (*C)(U*)>
dcp(U* u, copy_f<U, C> c) :
t(u),
c(type_erased_copy<U, C>)
{
}
public:
template <typename U>
dcp(U* u) :
dcp(u, copy_f<U, default_copy<U>>())
{
}
dcp(dcp const& other) :
t(std::unique_ptr<T>(static_cast<T*>(c(other.t.get())))),
c(other.c)
{
}
dcp(dcp&& other) :
t(std::move(other.t)),
c(other.c)
{
other.c = nullptr;
}
};
template <typename T, T* (*C)(T*) = default_copy<T>, typename... Ts>
dcp<T> make_dcp(Ts&&... ts)
{
return dcp<T>(new T(std::forward<Ts>(ts)...), copy_f<T, C>());
}
int main()
{
dcp<int> a{make_dcp<int>(42)};
dcp<int> b{make_dcp<int, default_copy<int>>(42)};
}
--
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/0dc0d8b3-538a-46bf-8e5d-af333ae32491%40isocpp.org.
------=_Part_1028_2095449904.1477731081514
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, 29 October 2016 03:28:50 UTC+8, Jonathan Coe =
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"auto"><div>=
</div><div><br></div><div><br>On 28 Oct 2016, at 17:49, <a href=3D"javascri=
pt:" target=3D"_blank" gdf-obfuscated-mailto=3D"kGYX56SGAwAJ" rel=3D"nofoll=
ow" onmousedown=3D"this.href=3D'javascript:';return true;" onclick=
=3D"this.href=3D'javascript:';return true;">mihailn...@gmail.com</a=
> wrote:<br><br></div><blockquote type=3D"cite"><div><div dir=3D"ltr"><br><=
br>On Wednesday, October 26, 2016 at 5:48:43 PM UTC+3, Jonathan Coe 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">On 26 October 2016 =
at 15:30, Ville Voutilainen <span dir=3D"ltr"><<a rel=3D"nofollow">ville=
..vo...@gmail.com</a>></span> wrote:<br><div><div class=3D"gmail_quote"><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
#ccc solid;padding-left:1ex"><span>On 26 October 2016 at 17:19, Jonathan C=
oe <<a rel=3D"nofollow">jb...@me.com</a>> wrote:<br>
....<br>
<br>
</span>I don't see how that could be achieved. The combined object that=
holds<br>
both the deleter<br>
and the object inside it would need to be exposed, and that's an<br>
implementation-internal<br>
type. Ripping apart the pointer and the deleter once they have been<br>
combined is not possible.<br>
<span><br></span></blockquote><div><br></div><div>That was my impression to=
o.</div></div></div></div></blockquote><div><br></div><div>Here is=C2=A0str=
iped-down version of the possible solution I was suggesting - to remove &qu=
ot;direct_control_block" and store the unique_ptr directly in the clas=
s</div><div><br></div><div>This case will be valid and well behaved until a=
converting assignment is made. At that point we move the unique_ptr into a=
pointer_control_block and continue as usual</div><div><br></div><div><br><=
/div><div><a href=3D"http://melpon.org/wandbox/permlink/PPC3kSC5lZqMcXwi" t=
arget=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'http://ww=
w.google.com/url?q\x3dhttp%3A%2F%2Fmelpon.org%2Fwandbox%2Fpermlink%2FPPC3kS=
C5lZqMcXwi\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzAyYfh1H0PHMUKunCXCY6Uh=
PwJw';return true;" onclick=3D"this.href=3D'http://www.google.com/u=
rl?q\x3dhttp%3A%2F%2Fmelpon.org%2Fwandbox%2Fpermlink%2FPPC3kSC5lZqMcXwi\x26=
sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzAyYfh1H0PHMUKunCXCY6UhPwJw';retu=
rn true;">http://melpon.org/wandbox/<wbr>permlink/PPC3kSC5lZqMcXwi</a></div=
><div><br></div><div><br></div><div>I think this makes it possible to have =
both release(), and no extra allocations, because, for the base case, we do=
n't use a control block.</div><div><br></div><div>The user will pay ext=
ra only if he/she uses extra functionality (virtual copy and/or type erasur=
e). </div><div><br></div><div>Please, comment. </div><div><br></div></div><=
/div></blockquote><div><br></div>This looks awesome.<div><br></div><div>Dep=
ending on the advice from LEWG regarding custom deleters and copiers this m=
ay or may not be possible. If make_indirect needs to take a custom deleters=
and copier (currently it does not) then your optimisation is ruled out. As=
things stand, it works and enables release().</div><div><br></div><div>Tha=
nks for taking the time to put this together.<br></div></div></blockquote><=
div><br>If you require the copier and deleter to be function pointers, then=
you can implement type erasure without virtual dispatch.=C2=A0 I don't=
think there is precident for this in the standard library though.<br><br><=
div style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 1=
87, 187); border-style: solid; border-width: 1px; overflow-wrap: break-word=
;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprett=
yprint"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">#include</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #080;" class=3D"styled-by-prettify"><memory></span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">*</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">T</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">*)></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> copy_f </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">template</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: #008;" class=3D"styled-by-p=
rettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(*</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">C</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">*)></span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">voi=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> type_erased_copy<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> v</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"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> C</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">stat=
ic_cast</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">*>(</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">v</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><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</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: #008;" class=3D"styled-by-p=
rettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>T</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> default_copy</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> t</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">new</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(*</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">t</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><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">template</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: #008;" class=3D"styled-by-prettify">type=
name</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">></span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> dcp<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>=C2=A0 =C2=A0 </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> U</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(*)(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">U</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">*),</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">typename</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">...</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pr=
ettify">Ts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">friend</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
dcp</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">U</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> make_dcp</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">&&...);</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">private</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">unique_ptr</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">></span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(*</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">c</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">)(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">void</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">*)</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">nullptr</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> U</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(*=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">C</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">)(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">U</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">*)></span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 dcp</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">U</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> u</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> copy_f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
<</span><span style=3D"color: #000;" class=3D"styled-by-prettify">U</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> C</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">></span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> c</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"styled-by=
-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 t</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">u</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 c</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">type_erased_copy</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">U</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> C<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">>)</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">public</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">template</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=
: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 dcp</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">U</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> u</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"styled-by-prettify">:</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 dcp</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">u</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> copy_f</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">U</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> default_copy</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">U</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">>>())</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br><br>=C2=A0 =C2=A0 dcp</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">dcp </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">const</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> other</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">unique_ptr</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">>(</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">static_cast</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">*>(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">c</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">other</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">t</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">get</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">())))),</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 c</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">other</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">c</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br>=C2=A0 =C2=A0 dcp</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">dcp</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&&</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> other</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 t</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">move</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">other</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">t</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">)),</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 c</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">other</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">c</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 other</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">c </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">nullptr</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">template</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: #008;" class=3D"st=
yled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(*</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">C</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">)(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">*)</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> defaul=
t_copy</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">>,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>dcp</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> make_dcp</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">Ts</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&&...</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> ts</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> dcp</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify"><</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">new</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">forward</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">>(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">ts</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)...),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
copy_f</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> C</span><span style=3D"colo=
r: #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><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> main</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 dcp</span><span style=3D"color: #080;" class=3D"styled-by-prettify">=
<int></span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">make_dcp</span><=
span style=3D"color: #080;" class=3D"styled-by-prettify"><int></span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #066;" class=3D"styled-by-prettify">42</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)};</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 dcp</span><span style=
=3D"color: #080;" class=3D"styled-by-prettify"><int></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> b</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">make_dcp</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> default_copy</span><span style=3D"color: #080;" class=3D"styled-by=
-prettify"><int></span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">>(</span><span style=3D"color: #066;" class=3D"styled-by-pre=
ttify">42</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></div>=
</code></div><br><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/0dc0d8b3-538a-46bf-8e5d-af333ae32491%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0dc0d8b3-538a-46bf-8e5d-af333ae32491=
%40isocpp.org</a>.<br />
------=_Part_1028_2095449904.1477731081514--
------=_Part_1027_1723866445.1477731081513--
.
Author: mihailnajdenov@gmail.com
Date: Sat, 29 Oct 2016 03:30:50 -0700 (PDT)
Raw View
------=_Part_832_1052239144.1477737050975
Content-Type: multipart/alternative;
boundary="----=_Part_833_1735652656.1477737050975"
------=_Part_833_1735652656.1477737050975
Content-Type: text/plain; charset=UTF-8
There is a small mistake
the copy ctor must call other.c(...), not c(...)
dcp(dcp const& other) :
t(std::unique_ptr<T>(static_cast<T*>(other.c(other.t.get())))),
c(other.c)
{
}
Otherwise, yes, this a neat trick - it is used for the "fastest delegates"
implementation.
However this does not work with virtual inheritance as the static_cast will
not cut it.
BTW if you study the commit history on the indirect<>, you will see many,
many interesting things.
For instance it was originally called *deep_ptr*! The very first name I
suggested!
Also, at some point it did have* non-empty state* - as you suggested!
One of the major changes came when Gustafsson pointed out the problems with
multiple and virtual inheritance - this lead to this control block design.
For me personally two things are essential
- to be zero cost for the non-polymorphic case, because it must be usable
for copyable big values like buffers. ***
- to be opt-out, because in the end it is just a (smart) package - nothing
more.
*** One extra field of study is - what does it mean to have ref-counted
copier. Will it be correct? What the const mean? Other issues?
This will enable easy wrapping C/Objective-C and other low level function
calls into an "RAII" class.
Objective-C is a prime user, not only because [retain/release] but because
it likes to use low level C idioms like global functions and counters:
it_is_safe_to_kill_my_app++ / it_is_safe_to_kill_my_app--,
begin_access_bookmarck() / end_access_bookmarck().
I will not touch these without RAII help. Ever.
So my hope is indirect<> to include not just polymorphic advanced cases,
but these simple cases as well - will save me writing yet another wrapper
class from scratch just to express the same idea.
My hope is for indirect<> to fill the "RAII" gap b/w do stuff on alloc
and do stuff on destroy - do stuff on copy.
I don't think these uses are the core of indirect, but I think they should
be seriously considered to improve its reuse.
Same goes for its name. Many uses might involve no indirection or even
pointers or heap alloc.
And that's the key - is polymorphic the main incentive OR
"create"-"copy"-"destroy" "data" combo in general (with possible abuses for
"RAII") OR both?
--
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/49964fe5-25bc-4a5c-a74d-ef1902caa889%40isocpp.org.
------=_Part_833_1735652656.1477737050975
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>There is a small mistake</div><div><br></div><div>the=
copy ctor must call other.c(...), not c(...)</div><div class=3D"prettyprin=
t" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; ba=
ckground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"b=
ackground-color: transparent;"><span class=3D"styled-by-prettify" style=3D"=
color: #000;">=C2=A0dcp</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #660;">(</span><span class=3D"styled-by-prettify" style=3D"color: #00=
0;">dcp </span><span class=3D"styled-by-prettify" style=3D"color: #008;">co=
nst</span><span class=3D"styled-by-prettify" style=3D"color: #660;">&</=
span><span class=3D"styled-by-prettify" style=3D"color: #000;"> other</span=
><span class=3D"styled-by-prettify" style=3D"color: #660;">)</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"st=
yled-by-prettify" style=3D"color: #660;">:</span><span class=3D"styled-by-p=
rettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 t</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;">std</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">::</span><span class=3D"styled-by-p=
rettify" style=3D"color: #000;">unique_ptr</span><span class=3D"styled-by-p=
rettify" style=3D"color: #660;"><</span><span class=3D"styled-by-prettif=
y" style=3D"color: #000;">T</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">>(</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #008;">static_cast</span><span class=3D"styled-by-prettify" style=3D"=
color: #660;"><</span><span class=3D"styled-by-prettify" style=3D"color:=
#000;">T</span><span class=3D"styled-by-prettify" style=3D"color: #660;">*=
>(</span><span class=3D"styled-by-prettify" style=3D"color: #000;">other=
</span><span class=3D"styled-by-prettify" style=3D"color: #660;">.</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;">c</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">(</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;">other</span><span class=3D"styled-by-=
prettify" style=3D"color: #660;">.</span><span class=3D"styled-by-prettify"=
style=3D"color: #000;">t</span><span class=3D"styled-by-prettify" style=3D=
"color: #660;">.</span><span class=3D"styled-by-prettify" style=3D"color: #=
008;">get</span><span class=3D"styled-by-prettify" style=3D"color: #660;">(=
))))),</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 c</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #660;">(</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #000;">other</span><span class=3D"styled-by-prettify" style=3D"color: #6=
60;">.</span><span class=3D"styled-by-prettify" style=3D"color: #000;">c</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #660;">)</span><span=
class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;">{</span><span =
class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </spa=
n><span class=3D"styled-by-prettify" style=3D"color: #660;">}</span></font>=
</div></code></div><div><br></div><div>Otherwise, yes, this a neat trick - =
it is used for the "fastest=C2=A0delegates" implementation. </div=
><div><br></div><div>However this does not work with virtual inheritance as=
the static_cast will not cut it.</div><div><br></div><div><br></div><div>B=
TW if you=C2=A0study the commit history on the indirect<>, you will s=
ee many, many interesting things.</div><div><br></div><div>For instance it =
was originally called <b>deep_ptr</b>! The very first name I suggested! </d=
iv><div>Also, at some point it did have<b> non-empty state</b> - as you sug=
gested!</div><div><br></div><div>One of the major changes came when Gustafs=
son pointed out the problems with multiple and virtual inheritance - this l=
ead to this control block design.</div><div><br></div><div><br></div><div>F=
or me personally two things are essential </div><div>=C2=A0- to be zero cos=
t for the non-polymorphic case, because it must be usable for copyable=C2=
=A0big values like buffers. ***=C2=A0</div><div>=C2=A0- to be opt-out, beca=
use in the end it is just a=C2=A0(smart)=C2=A0package - nothing more. </div=
><div><br></div><div>***=C2=A0One extra field of study is - what does it me=
an to have ref-counted copier. Will it be correct? What the const mean? Oth=
er issues?</div><div>This will enable easy wrapping C/Objective-C and other=
low level function calls into an "RAII" class. </div><div>Object=
ive-C is a prime user, not only because [retain/release] but because it lik=
es to use low level C idioms like global functions and counters:</div><div>=
it_is_safe_to_kill_my_app++=C2=A0/ it_is_safe_to_kill_my_app--, begin_acces=
s_bookmarck()=C2=A0/ end_access_bookmarck(). </div><div>I will not touch th=
ese without RAII help. Ever.</div><div><br></div><div>So my hope is indirec=
t<> to include not just polymorphic advanced cases, but these simple =
cases as well - will save me writing yet another wrapper class from scratch=
just to express the same idea.</div><div>My hope is for indirect<> t=
o fill the "RAII" gap b/w do stuff on alloc and=C2=A0do stuff on =
destroy - do stuff on copy. </div><div><br></div><div>I don't think the=
se uses are the core of indirect, but I think they should be seriously=C2=
=A0considered to improve its=C2=A0reuse.</div><div>Same goes for its name. =
Many uses might involve no indirection or even pointers or heap alloc.</div=
><div><br></div><div>And that's the key - is polymorphic the main incen=
tive OR "create"-"copy"-"destroy" "data&=
quot; combo=C2=A0in general (with possible=C2=A0abuses for "RAII"=
) OR=C2=A0both? </div><div><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/49964fe5-25bc-4a5c-a74d-ef1902caa889%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/49964fe5-25bc-4a5c-a74d-ef1902caa889=
%40isocpp.org</a>.<br />
------=_Part_833_1735652656.1477737050975--
------=_Part_832_1052239144.1477737050975--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 29 Oct 2016 14:15:06 +0300
Raw View
On 29 October 2016 at 13:30, <mihailnajdenov@gmail.com> wrote:
> And that's the key - is polymorphic the main incentive OR
> "create"-"copy"-"destroy" "data" combo in general (with possible abuses for
> "RAII") OR both?
cloned_ptr and indirect have been aiming for the polymorphic cases
from the very beginning. If you need
generic RAII and nothing else, see
http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0052r2.pdf
--
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/CAFk2RUYuBfTF_7tichvwRQox2CS3D7cLwnop__AnLSYsGr_5XA%40mail.gmail.com.
.
Author: mihailnajdenov@gmail.com
Date: Sat, 29 Oct 2016 06:36:14 -0700 (PDT)
Raw View
------=_Part_886_526757479.1477748175098
Content-Type: multipart/alternative;
boundary="----=_Part_887_652272025.1477748175099"
------=_Part_887_652272025.1477748175099
Content-Type: text/plain; charset=UTF-8
On Saturday, October 29, 2016 at 2:15:15 PM UTC+3, Ville Voutilainen wrote:
>
> On 29 October 2016 at 13:30, <mihailn...@gmail.com <javascript:>> wrote:
> > And that's the key - is polymorphic the main incentive OR
> > "create"-"copy"-"destroy" "data" combo in general (with possible abuses
> for
> > "RAII") OR both?
>
>
> cloned_ptr and indirect have been aiming for the polymorphic cases
> from the very beginning. If you need
> generic RAII and nothing else, see
> http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0052r2.pdf
> <http://www.google.com/url?q=http%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2016%2Fp0052r2.pdf&sa=D&sntz=1&usg=AFQjCNHkmqjE62zcI4PaP0X9tZzWQQAzfw>
>
You are right, I was using RAII a bit loosely.
Still, besides poly uses, I think it should handle simple data container
cases also.
At some point a user will need "a copyable unique_ptr" and there is nothing
but writhing their own (though, relatively trivial).
Then later they (or someone else) will use it by mistake polymorphically
and will shoot themselves in the foot.
I really think, this should be the go-to class for any copyable heap data.
And that should be reflected in the name better as well.
If we assume {malloc, memcpy, free} is valid and encouraged use, then
'indirect' is very confusing.
As for the ref count wrapper case - even if not designed for, people will
try it any way!
struct GFile_copier
{
GFile* operator()(const GFile & f) const
{
return g_file_dup (const_cast<GFile*>(&f));
}
};
struct GFile_deleter
{
void operator()(GFile* f) const
{
g_object_unref(f);
}
};
//----------------------
struct EXIFData_copier
{
EXIFData* operator()(const EXIFData & f) const
{
return exif_entry_ref(const_cast<EXIFData*>(&f));
}
};
struct EXIFData_deleter
{
void operator()(EXIFData* f) const
{
exif_data_unref(f);
}
};
//---------
People WILL (try to) write this! I know I would. It better be supported!
"Real world" cases like this make release() and zero-overhead very
important.
--
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/5465d67c-bca9-4648-ad37-9eeacf969efe%40isocpp.org.
------=_Part_887_652272025.1477748175099
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Saturday, October 29, 2016 at 2:15:15 PM UTC+3,=
Ville Voutilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 29=
October 2016 at 13:30, =C2=A0<<a onmousedown=3D"this.href=3D'javasc=
ript:';return true;" onclick=3D"this.href=3D'javascript:';retur=
n true;" href=3D"javascript:" target=3D"_blank" rel=3D"nofollow" gdf-obfusc=
ated-mailto=3D"0qu-P0q6AwAJ">mihailn...@gmail.com</a>> wrote:
<br>> And that's the key - is polymorphic the main incentive OR
<br>> "create"-"copy"-"destroy" "data=
" combo in general (with possible abuses for
<br>> "RAII") OR both?
<br>
<br>
<br>cloned_ptr and indirect have been aiming for the polymorphic cases
<br>from the very beginning. If you need
<br>generic RAII and nothing else, see
<br><a onmousedown=3D"this.href=3D'http://www.google.com/url?q\x3dhttp%=
3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2016%2Fp0052r2.=
pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHkmqjE62zcI4PaP0X9tZzWQQAzfw=
9;;return true;" onclick=3D"this.href=3D'http://www.google.com/url?q\x3=
dhttp%3A%2F%2Fopen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2016%2Fp0=
052r2.pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHkmqjE62zcI4PaP0X9tZzWQQA=
zfw';return true;" href=3D"http://www.google.com/url?q=3Dhttp%3A%2F%2Fo=
pen-std.org%2FJTC1%2FSC22%2FWG21%2Fdocs%2Fpapers%2F2016%2Fp0052r2.pdf&s=
a=3DD&sntz=3D1&usg=3DAFQjCNHkmqjE62zcI4PaP0X9tZzWQQAzfw" target=3D"=
_blank" rel=3D"nofollow">http://open-std.org/JTC1/SC22/<wbr>WG21/docs/paper=
s/2016/p0052r2.<wbr>pdf</a>
<br></blockquote><div><br></div><div>You are right, I was using RAII a bit =
loosely.</div><div><br></div><div>Still, besides poly uses, I think it shou=
ld handle simple data container cases also.</div><div>At some point a user =
will need "a copyable unique_ptr" and there is nothing but writhi=
ng their own (though, relatively trivial). </div><div>Then later they (or s=
omeone else)=C2=A0will use it by mistake polymorphically and will shoot the=
mselves in the foot. </div><div><br></div><div>I really think, this should =
be the go-to class for any copyable heap data.</div><div><br></div><div>And=
that should be reflected in the name better as well.</div><div>If we assum=
e {malloc, memcpy, free}=C2=A0is valid and encouraged use, then 'indire=
ct' is very confusing. </div><div><br></div><div><br></div><div>As for =
the ref count wrapper case - even if not designed for, people will try it a=
ny way!</div><div><br></div><div class=3D"prettyprint" style=3D"border: 1px=
solid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250=
, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><fo=
nt color=3D"#222222" face=3D"Arial"><span class=3D"styled-by-prettify" styl=
e=3D"color: #008;">struct</span><span class=3D"styled-by-prettify" style=3D=
"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color: #=
606;">GFile_copier</span><span class=3D"styled-by-prettify" style=3D"color:=
#000;"><br></span><span class=3D"styled-by-prettify" style=3D"color: #660;=
">{</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=
=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #606;">GFile<=
/span><span class=3D"styled-by-prettify" style=3D"color: #660;">*</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #008;">operator</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">()(</span><span class=3D"sty=
led-by-prettify" style=3D"color: #008;">const</span><span class=3D"styled-b=
y-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettif=
y" style=3D"color: #606;">GFile</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"co=
lor: #660;">&</span><span class=3D"styled-by-prettify" style=3D"color: =
#000;"> f</span><span class=3D"styled-by-prettify" style=3D"color: #660;">)=
</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </span><s=
pan class=3D"styled-by-prettify" style=3D"color: #008;">const</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 </span><span =
class=3D"styled-by-prettify" style=3D"color: #660;">{</span><span class=3D"=
styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span c=
lass=3D"styled-by-prettify" style=3D"color: #008;">return</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> g_file_dup </span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #660;">(</span><span class=3D"sty=
led-by-prettify" style=3D"color: #008;">const_cast</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;"><</span><span class=3D"styled-by=
-prettify" style=3D"color: #606;">GFile</span><span class=3D"styled-by-pret=
tify" style=3D"color: #660;">*>(&</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #000;">f</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #660;">));</span><span class=3D"styled-by-prettify" style=3D"=
color: #000;"><br>=C2=A0 </span><span class=3D"styled-by-prettify" style=3D=
"color: #660;">}</span><span class=3D"styled-by-prettify" style=3D"color: #=
000;"><br></span><span class=3D"styled-by-prettify" style=3D"color: #660;">=
};</span></font><div><font color=3D"#222222" face=3D"Arial" style=3D"backgr=
ound-color: transparent;"><span class=3D"styled-by-prettify" style=3D"color=
: #000;"><br></span></font><font color=3D"rgb(34,34,34)" face=3D"Arial" sty=
le=3D"background-color: transparent;"><span class=3D"styled-by-prettify" st=
yle=3D"color: #008;">struct</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color=
: #606;">GFile_deleter</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;"><br></span><span class=3D"styled-by-prettify" style=3D"color: #=
660;">{</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br=
>=C2=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #008;">vo=
id</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </span>=
<span class=3D"styled-by-prettify" style=3D"color: #008;">operator</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #660;">()(</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #606;">GFile</span><span class=3D=
"styled-by-prettify" style=3D"color: #660;">*</span><span class=3D"styled-b=
y-prettify" style=3D"color: #000;"> f</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #660;">)</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color=
: #008;">const</span><span class=3D"styled-by-prettify" style=3D"color: #00=
0;"><br>=C2=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #6=
60;">{</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=
=C2=A0 =C2=A0 g_object_</span><font color=3D"#000000"><span class=3D"styled=
-by-prettify" style=3D"color: #000;">unref</span><span class=3D"styled-by-p=
rettify" style=3D"color: #660;">(</span></font><font color=3D"#000000"><spa=
n class=3D"styled-by-prettify" style=3D"color: #000;">f</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">);</span></font><span class=
=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 </span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">}</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;"><br></span><span class=3D"styled-by-=
prettify" style=3D"color: #660;">};</span><span class=3D"styled-by-prettify=
" style=3D"color: #000;"><br><br></span><span class=3D"styled-by-prettify" =
style=3D"color: #800;">//----------------------</span><span class=3D"styled=
-by-prettify" style=3D"color: #000;"><br><br></span><font color=3D"#222222"=
><span class=3D"styled-by-prettify" style=3D"color: #008;">struct</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #606;">EXIFData_copier</span><span =
class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">{</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"><br>=C2=A0 </span><span class=3D"styl=
ed-by-prettify" style=3D"color: #606;">EXIFData</span><span class=3D"styled=
-by-prettify" style=3D"color: #660;">*</span><span class=3D"styled-by-prett=
ify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify" styl=
e=3D"color: #008;">operator</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">()(</span><span class=3D"styled-by-prettify" style=3D"col=
or: #008;">const</span><span class=3D"styled-by-prettify" style=3D"color: #=
000;"> </span><span class=3D"styled-by-prettify" style=3D"color: #606;">EXI=
FData</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> </sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;">&</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;"> f</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">)</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-pre=
ttify" style=3D"color: #008;">const</span><span class=3D"styled-by-prettify=
" style=3D"color: #000;"><br>=C2=A0 </span><span class=3D"styled-by-prettif=
y" style=3D"color: #660;">{</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettif=
y" style=3D"color: #008;">return</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #000;"> exif_entry_ref</span><span class=3D"styled-by-pretti=
fy" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" style=
=3D"color: #008;">const_cast</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;"><</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #606;">EXIFData</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #660;">*>(&</span><span class=3D"styled-by-prettify" style=3D"col=
or: #000;">f</span><span class=3D"styled-by-prettify" style=3D"color: #660;=
">));</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=
=C2=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #660;">}</=
span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><=
span class=3D"styled-by-prettify" style=3D"color: #660;">};</span></font><d=
iv><font color=3D"#222222" face=3D"Arial" style=3D"background-color: transp=
arent;"><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></spa=
n></font><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-c=
olor: transparent;"><span class=3D"styled-by-prettify" style=3D"color: #008=
;">struct</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> =
</span><span class=3D"styled-by-prettify" style=3D"color: #606;">EXIFData_d=
eleter</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=
</span><span class=3D"styled-by-prettify" style=3D"color: #660;">{</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 </span><=
span class=3D"styled-by-prettify" style=3D"color: #008;">void</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"s=
tyled-by-prettify" style=3D"color: #008;">operator</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">()(</span><span class=3D"styled-by-=
prettify" style=3D"color: #606;">EXIFData</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #660;">*</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #000;"> f</span><span class=3D"styled-by-prettify" style=3D"=
color: #660;">)</span><span class=3D"styled-by-prettify" style=3D"color: #0=
00;"> </span><span class=3D"styled-by-prettify" style=3D"color: #008;">cons=
t</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=
=A0 </span><span class=3D"styled-by-prettify" style=3D"color: #660;">{</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=
=A0 exif_data_unref</span><font color=3D"#000000"><span class=3D"styled-by-=
prettify" style=3D"color: #660;">(</span></font><font color=3D"#000000"><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;">f</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">);</span></font><span class=
=3D"styled-by-prettify" style=3D"color: #000;"><br>=C2=A0 </span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">}</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;"><br></span><span class=3D"styled-by-=
prettify" style=3D"color: #660;">};</span><span class=3D"styled-by-prettify=
" style=3D"color: #000;"><br><br></span><span class=3D"styled-by-prettify" =
style=3D"color: #800;">//---------</span></font><b></b><i></i><u></u><sub><=
/sub><sup></sup><strike></strike><span class=3D"styled-by-prettify" style=
=3D"color: #000;"><br></span></div><div></div></font><div></div></div></div=
></code></div><div><b><br></b></div><div><br></div><div>People WILL (try to=
) write this! I know I would. It better be supported!</div><div><br></div><=
div>"Real world" cases like this make release() and zero-overhead=
very important. </div><code class=3D"prettyprint"><div><br></div><div clas=
s=3D"subprettyprint"><pre style=3D" margin-top:0px; margin-bottom:0px; marg=
in-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br></=
pre></div></code><div class=3D"subprettyprint"><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/5465d67c-bca9-4648-ad37-9eeacf969efe%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5465d67c-bca9-4648-ad37-9eeacf969efe=
%40isocpp.org</a>.<br />
------=_Part_887_652272025.1477748175099--
------=_Part_886_526757479.1477748175098--
.
Author: joseph.thomson@gmail.com
Date: Sat, 29 Oct 2016 10:50:14 -0700 (PDT)
Raw View
------=_Part_410_1220394425.1477763414211
Content-Type: multipart/alternative;
boundary="----=_Part_411_1098670604.1477763414211"
------=_Part_411_1098670604.1477763414211
Content-Type: text/plain; charset=UTF-8
On Saturday, 29 October 2016 18:30:51 UTC+8, mihailn...@gmail.com wrote:
>
> There is a small mistake
>
> the copy ctor must call other.c(...), not c(...)
> dcp(dcp const& other) :
> t(std::unique_ptr<T>(static_cast<T*>(other.c(other.t.get())))),
> c(other.c)
> {
> }
>
> Otherwise, yes, this a neat trick - it is used for the "fastest delegates"
> implementation.
>
> However this does not work with virtual inheritance as the static_cast
> will not cut it.
>
That's annoying. However, in this case if there were a type trait,
has_virtual_base, then it would be possible to "specialize" the
type_erased_copy function to use dynamic_cast where necessary (I just
realised that type_erased_copy can take and return T*, and thus encapsulate
the casting). That way you get optimal performance and complete generality.
Maybe someone should propose such a type trait...
> BTW if you study the commit history on the indirect<>, you will see many,
> many interesting things.
>
> For instance it was originally called *deep_ptr*! The very first name I
> suggested!
> Also, at some point it did have* non-empty state* - as you suggested!
>
Just to clarify, I'd only recommend no empty state if the type is *not*
modelling a pointer, which is why I asked for clarification of the aim of
the proposal.
> One of the major changes came when Gustafsson pointed out the problems
> with multiple and virtual inheritance - this lead to this control block
> design.
>
I wonder if this design could be optimized if a has_virtual_base type trait
existed.
For me personally two things are essential
> - to be zero cost for the non-polymorphic case, because it must be usable
> for copyable big values like buffers. ***
> - to be opt-out, because in the end it is just a (smart) package -
> nothing more.
>
The implementation could be specialized on the is_polymorphic type trait.
This would give you minimal overhead for non-polymorphic types.
*** One extra field of study is - what does it mean to have ref-counted
> copier. Will it be correct? What the const mean? Other issues?
> This will enable easy wrapping C/Objective-C and other low level function
> calls into an "RAII" class.
> Objective-C is a prime user, not only because [retain/release] but because
> it likes to use low level C idioms like global functions and counters:
> it_is_safe_to_kill_my_app++ / it_is_safe_to_kill_my_app--,
> begin_access_bookmarck() / end_access_bookmarck().
> I will not touch these without RAII help. Ever.
>
> So my hope is indirect<> to include not just polymorphic advanced cases,
> but these simple cases as well - will save me writing yet another wrapper
> class from scratch just to express the same idea.
> My hope is for indirect<> to fill the "RAII" gap b/w do stuff on alloc
> and do stuff on destroy - do stuff on copy.
>
> I don't think these uses are the core of indirect, but I think they should
> be seriously considered to improve its reuse.
> Same goes for its name. Many uses might involve no indirection or even
> pointers or heap alloc.
>
> And that's the key - is polymorphic the main incentive OR
> "create"-"copy"-"destroy" "data" combo in general (with possible abuses for
> "RAII") OR both?
>
>
--
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/e3fd9c77-c3f7-4b0c-ba00-00edb25fe106%40isocpp.org.
------=_Part_411_1098670604.1477763414211
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, 29 October 2016 18:30:51 UTC+8, mihailn...@gm=
ail.com 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>There is a small mistake</div><div><br></div><div>the copy ctor must=
call other.c(...), not c(...)</div><div style=3D"border:1px solid rgb(187,=
187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div=
><font style=3D"background-color:transparent" color=3D"rgb(34,34,34)" face=
=3D"Arial"><span style=3D"color:#000">=C2=A0dcp</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">dcp </span><span style=3D"color:#0=
08">const</span><span style=3D"color:#660">&</span><span style=3D"color=
:#000"> other</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">:</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 t</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#000">std</span><span style=3D"color:#660">::</span>=
<span style=3D"color:#000">unique_ptr</span><span style=3D"color:#660"><=
</span><span style=3D"color:#000">T</span><span style=3D"color:#660">>(<=
/span><span style=3D"color:#008">static_<wbr>cast</span><span style=3D"colo=
r:#660"><</span><span style=3D"color:#000">T</span><span style=3D"color:=
#660">*>(</span><span style=3D"color:#000">other</span><span style=3D"co=
lor:#660">.</span><span style=3D"color:#000">c</span><span style=3D"color:#=
660">(</span><span style=3D"color:#000">other</span><span style=3D"color:#6=
60">.</span><span style=3D"color:#000">t</span><span style=3D"color:#660">.=
</span><span style=3D"color:#008">get</span><span style=3D"color:#660">()<w=
br>)))),</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 c=
</span><span style=3D"color:#660">(</span><span style=3D"color:#000">other<=
/span><span style=3D"color:#660">.</span><span style=3D"color:#000">c</span=
><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">{</span><span style=3D"color:#000"=
><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span></font></div><=
/code></div><div><br></div><div>Otherwise, yes, this a neat trick - it is u=
sed for the "fastest=C2=A0delegates" implementation. </div><div><=
br></div><div>However this does not work with virtual inheritance as the st=
atic_cast will not cut it.</div></div></blockquote><div><br>That's anno=
ying. However, in this case if there were a type trait, <span style=3D"font=
-family: courier new,monospace;">has_virtual_base</span>, then it would be =
possible to "specialize" the <span style=3D"font-family: courier =
new,monospace;">type_erased_copy</span> function to use <span style=3D"font=
-family: courier new,monospace;">dynamic_cast</span> where necessary (I jus=
t realised that <span style=3D"font-family: courier new,monospace;">type_er=
ased_copy</span> can take and return <span style=3D"font-family: courier ne=
w,monospace;">T*</span>, and thus encapsulate the casting). That way you ge=
t optimal performance and complete generality. Maybe someone should propose=
such a type trait...<br>=C2=A0</div><blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
1ex;"><div dir=3D"ltr"><div></div><div>BTW if you=C2=A0study the commit hi=
story on the indirect<>, you will see many, many interesting things.<=
/div><div><br></div><div>For instance it was originally called <b>deep_ptr<=
/b>! The very first name I suggested! </div><div>Also, at some point it did=
have<b> non-empty state</b> - as you suggested!</div></div></blockquote><d=
iv><br>Just to clarify, I'd only recommend no empty state if the type i=
s <i>not</i> modelling a pointer, which is why I asked for clarification of=
the aim of the proposal.<br>=C2=A0</div><blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr"><div></div><div>One of the major changes came w=
hen Gustafsson pointed out the problems with multiple and virtual inheritan=
ce - this lead to this control block design.</div></div></blockquote><div><=
br>I wonder if this design could be optimized if a <span style=3D"font-fami=
ly: courier new,monospace;">has_virtual_base<span style=3D"font-family: ari=
al,sans-serif;"> type</span></span><span style=3D"font-family: arial,sans-s=
erif;"> </span>trait existed.<br><br></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>For me personally two things =
are essential </div><div>=C2=A0- to be zero cost for the non-polymorphic ca=
se, because it must be usable for copyable=C2=A0big values like buffers. **=
*=C2=A0</div><div>=C2=A0- to be opt-out, because in the end it is just a=C2=
=A0(smart)=C2=A0package - nothing more. </div></div></blockquote><div>=C2=
=A0<br>The implementation could be specialized on the <span style=3D"font-f=
amily: courier new,monospace;">is_polymorphic</span> type trait. This would=
give you minimal overhead for non-polymorphic types.<br><br></div><blockqu=
ote 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>***=
=C2=A0One extra field of study is - what does it mean to have ref-counted c=
opier. Will it be correct? What the const mean? Other issues?</div><div>Thi=
s will enable easy wrapping C/Objective-C and other low level function call=
s into an "RAII" class. </div><div>Objective-C is a prime user, n=
ot only because [retain/release] but because it likes to use low level C id=
ioms like global functions and counters:</div><div>it_is_safe_to_kill_my_ap=
p++=C2=A0/ it_is_safe_to_kill_my_app--, begin_access_bookmarck()=C2=A0/ end=
_access_bookmarck(). </div><div>I will not touch these without RAII help. E=
ver.</div><div><br></div><div>So my hope is indirect<> to include not=
just polymorphic advanced cases, but these simple cases as well - will sav=
e me writing yet another wrapper class from scratch just to express the sam=
e idea.</div><div>My hope is for indirect<> to fill the "RAII&qu=
ot; gap b/w do stuff on alloc and=C2=A0do stuff on destroy - do stuff on co=
py. </div><div><br></div><div>I don't think these uses are the core of =
indirect, but I think they should be seriously=C2=A0considered to improve i=
ts=C2=A0reuse.</div><div>Same goes for its name. Many uses might involve no=
indirection or even pointers or heap alloc.</div><div><br></div><div>And t=
hat's the key - is polymorphic the main incentive OR "create"=
-"copy"-"destroy" "data" combo=C2=A0in genera=
l (with possible=C2=A0abuses for "RAII") OR=C2=A0both? </div><div=
><br></div></div></blockquote></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/e3fd9c77-c3f7-4b0c-ba00-00edb25fe106%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e3fd9c77-c3f7-4b0c-ba00-00edb25fe106=
%40isocpp.org</a>.<br />
------=_Part_411_1098670604.1477763414211--
------=_Part_410_1220394425.1477763414211--
.
Author: mihailnajdenov@gmail.com
Date: Sat, 29 Oct 2016 13:17:01 -0700 (PDT)
Raw View
------=_Part_1197_229159975.1477772221872
Content-Type: multipart/alternative;
boundary="----=_Part_1198_1333078676.1477772221872"
------=_Part_1198_1333078676.1477772221872
Content-Type: text/plain; charset=UTF-8
On Saturday, October 29, 2016 at 8:50:14 PM UTC+3, joseph....@gmail.com
wrote:
>
> On Saturday, 29 October 2016 18:30:51 UTC+8, mihailn...@gmail.com wrote:
>>
>> There is a small mistake
>>
>> the copy ctor must call other.c(...), not c(...)
>> dcp(dcp const& other) :
>> t(std::unique_ptr<T>(static_cast<T*>(other.c(other.t.get())))),
>> c(other.c)
>> {
>> }
>>
>> Otherwise, yes, this a neat trick - it is used for the
>> "fastest delegates" implementation.
>>
>> However this does not work with virtual inheritance as the static_cast
>> will not cut it.
>>
>
> That's annoying. However, in this case if there were a type trait,
> has_virtual_base, then it would be possible to "specialize" the
> type_erased_copy function to use dynamic_cast where necessary (I just
> realised that type_erased_copy can take and return T*, and thus
> encapsulate the casting)
>
.....
>
This might work, we still need to cast the stub pointer - U*(*c)(U*) into
a T*(*c)(T*) - in order to store it, and I am not sure how safe it is.
In any case, it opens up interesting possibilities if valid. It is a bit
tricky to extend it make it work with functors, but it is not impossible.
The deleter is a different story though, it might even be worth it not to
use unique_ptr so we can have complete control.
--
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/57877fb5-6486-4ca4-9cab-5e69e98d8d92%40isocpp.org.
------=_Part_1198_1333078676.1477772221872
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br>On Saturday, October 29, 2016 at 8:50:14 PM UTC+3, jos=
eph....@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr">On Saturday, 29 October 2016 18:30:51 UTC+8, <a>mihailn...@gmail=
..com</a> 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"><d=
iv>There is a small mistake</div><div><br></div><div>the copy ctor must cal=
l other.c(...), not c(...)</div><div style=3D"border:1px solid rgb(187,187,=
187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><fo=
nt color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color:transpa=
rent"><span style=3D"color:#000">=C2=A0dcp</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#000">dcp </span><span style=3D"color:#008">c=
onst</span><span style=3D"color:#660">&</span><span style=3D"color:#000=
"> other</span><span style=3D"color:#660">)</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">:</span><span style=3D"color:#000"><br=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 t</span><span style=3D"color:#660">(</span><sp=
an style=3D"color:#000">std</span><span style=3D"color:#660">::</span><span=
style=3D"color:#000">unique_ptr</span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#000">T</span><span style=3D"color:#660">>(</span=
><span style=3D"color:#008">static_<wbr>cast</span><span style=3D"color:#66=
0"><</span><span style=3D"color:#000">T</span><span style=3D"color:#660"=
>*>(</span><span style=3D"color:#000">other</span><span style=3D"color:#=
660">.</span><span style=3D"color:#000">c</span><span style=3D"color:#660">=
(</span><span style=3D"color:#000">other</span><span style=3D"color:#660">.=
</span><span style=3D"color:#000">t</span><span style=3D"color:#660">.</spa=
n><span style=3D"color:#008">get</span><span style=3D"color:#660">()<wbr>))=
)),</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 c</spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#000">other</span=
><span style=3D"color:#660">.</span><span style=3D"color:#000">c</span><spa=
n style=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0=
</span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span></font></div></code=
></div><div><br></div><div>Otherwise, yes, this a neat trick - it is used f=
or the "fastest=C2=A0delegates" implementation. </div><div><br></=
div><div>However this does not work with virtual inheritance as the static_=
cast will not cut it.</div></div></blockquote><div><br>That's annoying.=
However, in this case if there were a type trait, <span style=3D"font-fami=
ly:courier new,monospace">has_virtual_base</span>, then it would be possibl=
e to "specialize" the <span style=3D"font-family:courier new,mono=
space">type_erased_copy</span> function to use <span style=3D"font-family:c=
ourier new,monospace">dynamic_cast</span> where necessary (I just realised =
that <span style=3D"font-family:courier new,monospace">type_erased_copy</sp=
an> can take and return <span style=3D"font-family:courier new,monospace">T=
*</span>, and thus encapsulate the casting)=C2=A0</div></div></blockquote><=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>....<br><=
/div></div></blockquote><div><br></div><div>This might work, we still need =
to cast the stub pointer - =C2=A0U*(*c)(U*) into a T*(*c)(T*)=C2=A0- in ord=
er to store it, and I am not sure how safe it is. </div><div>In any case, i=
t=C2=A0opens up interesting=C2=A0possibilities if valid. It is a bit tricky=
to extend it=C2=A0make it work with functors, but it is not impossible. </=
div><div>The deleter is a different story though, it might even be worth it=
not to use unique_ptr so we can have complete control.</div><div><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/57877fb5-6486-4ca4-9cab-5e69e98d8d92%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/57877fb5-6486-4ca4-9cab-5e69e98d8d92=
%40isocpp.org</a>.<br />
------=_Part_1198_1333078676.1477772221872--
------=_Part_1197_229159975.1477772221872--
.
Author: joseph.thomson@gmail.com
Date: Sat, 29 Oct 2016 19:09:01 -0700 (PDT)
Raw View
------=_Part_1605_1356337884.1477793341539
Content-Type: multipart/alternative;
boundary="----=_Part_1606_1781881696.1477793341539"
------=_Part_1606_1781881696.1477793341539
Content-Type: text/plain; charset=UTF-8
On Sunday, 30 October 2016 04:17:01 UTC+8, mihailn...@gmail.com wrote:
>
>
> On Saturday, October 29, 2016 at 8:50:14 PM UTC+3, joseph....@gmail.com
> wrote:
>>
>> On Saturday, 29 October 2016 18:30:51 UTC+8, mihailn...@gmail.com wrote:
>>>
>>> There is a small mistake
>>>
>>> the copy ctor must call other.c(...), not c(...)
>>> dcp(dcp const& other) :
>>> t(std::unique_ptr<T>(static_cast<T*>(other.c(other.t.get())))),
>>> c(other.c)
>>> {
>>> }
>>>
>>> Otherwise, yes, this a neat trick - it is used for the
>>> "fastest delegates" implementation.
>>>
>>> However this does not work with virtual inheritance as the static_cast
>>> will not cut it.
>>>
>>
>> That's annoying. However, in this case if there were a type trait,
>> has_virtual_base, then it would be possible to "specialize" the
>> type_erased_copy function to use dynamic_cast where necessary (I just
>> realised that type_erased_copy can take and return T*, and thus
>> encapsulate the casting)
>>
> ....
>>
>
> This might work, we still need to cast the stub pointer - U*(*c)(U*) into
> a T*(*c)(T*) - in order to store it, and I am not sure how safe it is.
> In any case, it opens up interesting possibilities if valid. It is a bit
> tricky to extend it make it work with functors, but it is not impossible.
> The deleter is a different story though, it might even be worth it not to
> use unique_ptr so we can have complete control.
>
>
I think I was a bit hasty in my analysis. I don't know whether such a thing
would be possible.
--
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/4e4e2562-3aee-40ee-b56e-f9993a166670%40isocpp.org.
------=_Part_1606_1781881696.1477793341539
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, 30 October 2016 04:17:01 UTC+8, mihailn=
....@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><br>On Saturday, October 29, 2016 at 8:50:14 PM UTC+3, <a>joseph..=
...@gmail.com</a> 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">On Saturday, 29 October 2016 18:30:51 UTC+8, <a>mihailn...@gmail.com</=
a> 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>The=
re is a small mistake</div><div><br></div><div>the copy ctor must call othe=
r.c(...), not c(...)</div><div style=3D"border:1px solid rgb(187,187,187);w=
ord-wrap:break-word;background-color:rgb(250,250,250)"><code><div><font sty=
le=3D"background-color:transparent" color=3D"rgb(34,34,34)" face=3D"Arial">=
<span style=3D"color:#000">=C2=A0dcp</span><span style=3D"color:#660">(</sp=
an><span style=3D"color:#000">dcp </span><span style=3D"color:#008">const</=
span><span style=3D"color:#660">&</span><span style=3D"color:#000"> oth=
er</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 t</span><span style=3D"color:#660">(</span><span s=
tyle=3D"color:#000">std</span><span style=3D"color:#660">::</span><span sty=
le=3D"color:#000">unique_ptr</span><span style=3D"color:#660"><</span><s=
pan style=3D"color:#000">T</span><span style=3D"color:#660">>(</span><sp=
an style=3D"color:#008">static_<wbr>cast</span><span style=3D"color:#660">&=
lt;</span><span style=3D"color:#000">T</span><span style=3D"color:#660">*&g=
t;(</span><span style=3D"color:#000">other</span><span style=3D"color:#660"=
>.</span><span style=3D"color:#000">c</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#000">other</span><span style=3D"color:#660">.</sp=
an><span style=3D"color:#000">t</span><span style=3D"color:#660">.</span><s=
pan style=3D"color:#008">get</span><span style=3D"color:#660">()<wbr>)))),<=
/span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 c</span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#000">other</span><sp=
an style=3D"color:#660">.</span><span style=3D"color:#000">c</span><span st=
yle=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </s=
pan><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#660">}</span></font></div></code></=
div><div><br></div><div>Otherwise, yes, this a neat trick - it is used for =
the "fastest=C2=A0delegates" implementation. </div><div><br></div=
><div>However this does not work with virtual inheritance as the static_cas=
t will not cut it.</div></div></blockquote><div><br>That's annoying. Ho=
wever, in this case if there were a type trait, <span style=3D"font-family:=
courier new,monospace">has_virtual_base</span>, then it would be possible t=
o "specialize" the <span style=3D"font-family:courier new,monospa=
ce">type_erased_copy</span> function to use <span style=3D"font-family:cour=
ier new,monospace">dynamic_cast</span> where necessary (I just realised tha=
t <span style=3D"font-family:courier new,monospace">type_erased_copy</span>=
can take and return <span style=3D"font-family:courier new,monospace">T*</=
span>, and thus encapsulate the casting)=C2=A0</div></div></blockquote><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-le=
ft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>....<br></div></d=
iv></blockquote><div><br></div><div>This might work, we still need to cast =
the stub pointer - =C2=A0U*(*c)(U*) into a T*(*c)(T*)=C2=A0- in order to st=
ore it, and I am not sure how safe it is. </div><div>In any case, it=C2=A0o=
pens up interesting=C2=A0possibilities if valid. It is a bit tricky to exte=
nd it=C2=A0make it work with functors, but it is not impossible. </div><div=
>The deleter is a different story though, it might even be worth it not to =
use unique_ptr so we can have complete control.</div><div><br></div></div><=
/blockquote><div><br>I think I was a bit hasty in my analysis. I don't =
know whether such a thing would be possible. <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/4e4e2562-3aee-40ee-b56e-f9993a166670%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4e4e2562-3aee-40ee-b56e-f9993a166670=
%40isocpp.org</a>.<br />
------=_Part_1606_1781881696.1477793341539--
------=_Part_1605_1356337884.1477793341539--
.
Author: mihailnajdenov@gmail.com
Date: Sun, 30 Oct 2016 07:21:14 -0700 (PDT)
Raw View
------=_Part_1364_1969165227.1477837274665
Content-Type: multipart/alternative;
boundary="----=_Part_1365_693685949.1477837274665"
------=_Part_1365_693685949.1477837274665
Content-Type: text/plain; charset=UTF-8
On Sunday, October 30, 2016 at 4:09:01 AM UTC+2, joseph....@gmail.com wrote:
>
>
>
> On Sunday, 30 October 2016 04:17:01 UTC+8, mihailn...@gmail.com wrote:
>>
>>
>> On Saturday, October 29, 2016 at 8:50:14 PM UTC+3, joseph....@gmail.com
>> wrote:
>>>
>>> On Saturday, 29 October 2016 18:30:51 UTC+8, mihailn...@gmail.com wrote:
>>>>
>>>> There is a small mistake
>>>>
>>>> the copy ctor must call other.c(...), not c(...)
>>>> dcp(dcp const& other) :
>>>> t(std::unique_ptr<T>(static_cast<T*>(other.c(other.t.get())))),
>>>> c(other.c)
>>>> {
>>>> }
>>>>
>>>> Otherwise, yes, this a neat trick - it is used for the
>>>> "fastest delegates" implementation.
>>>>
>>>> However this does not work with virtual inheritance as the static_cast
>>>> will not cut it.
>>>>
>>>
>>> That's annoying. However, in this case if there were a type trait,
>>> has_virtual_base, then it would be possible to "specialize" the
>>> type_erased_copy function to use dynamic_cast where necessary (I just
>>> realised that type_erased_copy can take and return T*, and thus
>>> encapsulate the casting)
>>>
>> ....
>>>
>>
>> This might work, we still need to cast the stub pointer - U*(*c)(U*)
>> into a T*(*c)(T*) - in order to store it, and I am not sure how safe it is.
>> In any case, it opens up interesting possibilities if valid. It is a bit
>> tricky to extend it make it work with functors, but it is not impossible.
>> The deleter is a different story though, it might even be worth it not to
>> use unique_ptr so we can have complete control.
>>
>>
>
I think I got this sucker working
These are the tricks
1) we store the original pointer (p) alongside the primary pointer of the
instance (t) . We use this original pointer to create copies, because it
will always be pointing either to the original or a copy of it.
It will always be the most derived class, satisfying all other pointers we
can be converted to.
2) then we just
template <typename T, T* (*C)(T*)>
void* type_erased_copy(void* v)
{
return C(reinterpret_cast<T*>(v));
}
in the copier.
3 ) Now the last very tricky part is to get the (possibly adjusted!)
primary pointer for the instance.
It is done by a special casting function
template<class T>
class dcp
{
....
template <class U>
U* cast_p(void* p) const
{
return static_cast<U*>(reinterpret_cast<T*>(p));
}
....
};
The trick is - it is a function witch has all the information to do correct
cast!
It is called like so
dcp(dcp const& other) :
t(std::unique_ptr<T>(other.cast_p<T>((p = other.c(other.p))))),
c(other.c)
{
}
As you can see we preserve all information all the time to do a correct
copy and cast and all is rooted to the original object (or copies of it)
as it is the most derived one, we can possibly assign to.
Here's a playable example
http://melpon.org/wandbox/permlink/QQR0B96fdWDx1Pqr
--
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/33a67392-1d55-40b4-ab15-22b91c8abc10%40isocpp.org.
------=_Part_1365_693685949.1477837274665
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, October 30, 2016 at 4:09:01 AM UTC+2, j=
oseph....@gmail.com 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"><br><br>On Sunday, 30 October 2016 04:17:01 UTC+8, <a>mihailn.=
...@gmail.com</a> 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"><br>On Saturday, October 29, 2016 at 8:50:14 PM UTC+3, <a>joseph....@=
gmail.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;mar=
gin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr=
">On Saturday, 29 October 2016 18:30:51 UTC+8, <a>mihailn...@gmail.com</a> =
wrote:<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"><div>There =
is a small mistake</div><div><br></div><div>the copy ctor must call other.c=
(...), not c(...)</div><div style=3D"border:1px solid rgb(187,187,187);word=
-wrap:break-word;background-color:rgb(250,250,250)"><code><div><font color=
=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color:transparent"><s=
pan style=3D"color:#000">=C2=A0dcp</span><span style=3D"color:#660">(</span=
><span style=3D"color:#000">dcp </span><span style=3D"color:#008">const</sp=
an><span style=3D"color:#660">&</span><span style=3D"color:#000"> other=
</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">:</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 t</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">unique_ptr</span><span style=3D"color:#660"><</span><spa=
n style=3D"color:#000">T</span><span style=3D"color:#660">>(</span><span=
style=3D"color:#008">static_<wbr>cast</span><span style=3D"color:#660"><=
;</span><span style=3D"color:#000">T</span><span style=3D"color:#660">*>=
(</span><span style=3D"color:#000">other</span><span style=3D"color:#660">.=
</span><span style=3D"color:#000">c</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#000">other</span><span style=3D"color:#660">.</span=
><span style=3D"color:#000">t</span><span style=3D"color:#660">.</span><spa=
n style=3D"color:#008">get</span><span style=3D"color:#660">()<wbr>)))),</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 c</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#000">other</span><span=
style=3D"color:#660">.</span><span style=3D"color:#000">c</span><span styl=
e=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">}</span></font></div></code></div>=
<div><br></div><div>Otherwise, yes, this a neat trick - it is used for the =
"fastest=C2=A0delegates" implementation. </div><div><br></div><di=
v>However this does not work with virtual inheritance as the static_cast wi=
ll not cut it.</div></div></blockquote><div><br>That's annoying. Howeve=
r, in this case if there were a type trait, <span style=3D"font-family:cour=
ier new,monospace">has_virtual_base</span>, then it would be possible to &q=
uot;specialize" the <span style=3D"font-family:courier new,monospace">=
type_erased_copy</span> function to use <span style=3D"font-family:courier =
new,monospace">dynamic_cast</span> where necessary (I just realised that <s=
pan style=3D"font-family:courier new,monospace">type_erased_copy</span> can=
take and return <span style=3D"font-family:courier new,monospace">T*</span=
>, and thus encapsulate the casting)=C2=A0</div></div></blockquote><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1=
px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>....<br></div></div><=
/blockquote><div><br></div><div>This might work, we still need to cast the =
stub pointer - =C2=A0U*(*c)(U*) into a T*(*c)(T*)=C2=A0- in order to store =
it, and I am not sure how safe it is. </div><div>In any case, it=C2=A0opens=
up interesting=C2=A0possibilities if valid. It is a bit tricky to extend i=
t=C2=A0make it work with functors, but it is not impossible. </div><div>The=
deleter is a different story though, it might even be worth it not to use =
unique_ptr so we can have complete control.</div><div><br></div></div></blo=
ckquote><div><br></div></div></blockquote><div><br></div><div>I think I got=
this sucker working</div><div><br></div><div>These are the tricks</div><di=
v><br></div><div>1)=C2=A0we store the original pointer (p)=C2=A0alongside t=
he primary pointer of the instance (t)=C2=A0. We use this original pointer =
to create copies, because it will always be pointing either to the original=
or a copy of it.</div><div>It will=C2=A0always be=C2=A0the most derived cl=
ass, satisfying=C2=A0all other pointers we can be converted to. </div><div>=
<br></div><div>2) then=C2=A0we just</div><div><br></div><div class=3D"prett=
yprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-wor=
d; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=
=3D"background-color: transparent;"><span class=3D"styled-by-prettify" styl=
e=3D"color: #008;">template</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color=
: #660;"><</span><span class=3D"styled-by-prettify" style=3D"color: #008=
;">typename</span><span class=3D"styled-by-prettify" style=3D"color: #000;"=
> T</span><span class=3D"styled-by-prettify" style=3D"color: #660;">,</span=
><span class=3D"styled-by-prettify" style=3D"color: #000;"> T</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #660;">*</span><span class=3D"s=
tyled-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-=
prettify" style=3D"color: #660;">(*</span><span class=3D"styled-by-prettify=
" style=3D"color: #000;">C</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">)(</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #000;">T</span><span class=3D"styled-by-prettify" style=3D"color: #660;"=
>*)></span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br=
></span><span class=3D"styled-by-prettify" style=3D"color: #008;">void</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #660;">*</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #000;"> type_erased_copy</span>=
<span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #008;">void</span><span class=3D"=
styled-by-prettify" style=3D"color: #660;">*</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;"> v</span><span class=3D"styled-by-prettif=
y" style=3D"color: #660;">)</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" style=3D"co=
lor: #660;">{</span><span class=3D"styled-by-prettify" style=3D"color: #000=
;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" style=3D"col=
or: #008;">return</span><span class=3D"styled-by-prettify" style=3D"color: =
#000;"> C</span><span class=3D"styled-by-prettify" style=3D"color: #660;">(=
</span><span class=3D"styled-by-prettify" style=3D"color: #008;">reinterpre=
t_cast</span><span class=3D"styled-by-prettify" style=3D"color: #660;"><=
</span><span class=3D"styled-by-prettify" style=3D"color: #000;">T</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #660;">*>(</span><span =
class=3D"styled-by-prettify" style=3D"color: #000;">v</span><span class=3D"=
styled-by-prettify" style=3D"color: #660;">));</span><span class=3D"styled-=
by-prettify" style=3D"color: #000;"><br></span><span class=3D"styled-by-pre=
ttify" style=3D"color: #660;">}</span></font></div></code></div><div><br>in=
the copier.</div><div><br></div><div>3 ) Now the last very tricky part is =
to get the (possibly=C2=A0adjusted!) primary pointer for the instance. </di=
v><div><br></div><div>It is done by a special casting function</div><div><b=
r></div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187,=
187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><=
code class=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"rgb=
(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;"><span c=
lass=3D"styled-by-prettify" style=3D"color: #008;">template</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #660;"><</span><span class=3D"=
styled-by-prettify" style=3D"color: #008;">class</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;"> T</span><span class=3D"styled-by-pre=
ttify" style=3D"color: #660;">></span><span class=3D"styled-by-prettify"=
style=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" style=
=3D"color: #008;">class</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #000;"> dcp<br></span><span class=3D"styled-by-prettify" style=3D"col=
or: #660;">{</span><span class=3D"styled-by-prettify" style=3D"color: #000;=
"><br></span><span class=3D"styled-by-prettify" style=3D"color: #660;">...<=
/span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></span>=
<span class=3D"styled-by-prettify" style=3D"color: #008;">template</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=
=3D"styled-by-prettify" style=3D"color: #660;"><</span><span class=3D"st=
yled-by-prettify" style=3D"color: #008;">class</span><span class=3D"styled-=
by-prettify" style=3D"color: #000;"> U</span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">></span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #000;"><br>U</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">*</span><span class=3D"styled-by-prettify" style=3D"color=
: #000;"> cast_p</span><span class=3D"styled-by-prettify" style=3D"color: #=
660;">(</span><span class=3D"styled-by-prettify" style=3D"color: #008;">voi=
d</span><span class=3D"styled-by-prettify" style=3D"color: #660;">*</span><=
span class=3D"styled-by-prettify" style=3D"color: #000;"> p</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #660;">)</span><span class=3D"sty=
led-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-pr=
ettify" style=3D"color: #008;">const</span><span class=3D"styled-by-prettif=
y" style=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" sty=
le=3D"color: #660;">{</span><span class=3D"styled-by-prettify" style=3D"col=
or: #000;"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettify" styl=
e=3D"color: #008;">return</span><span class=3D"styled-by-prettify" style=3D=
"color: #000;"> </span><span class=3D"styled-by-prettify" style=3D"color: #=
008;">static_cast</span><span class=3D"styled-by-prettify" style=3D"color: =
#660;"><</span><span class=3D"styled-by-prettify" style=3D"color: #000;"=
>U</span><span class=3D"styled-by-prettify" style=3D"color: #660;">*>(</=
span><span class=3D"styled-by-prettify" style=3D"color: #008;">reinterpret_=
cast</span><span class=3D"styled-by-prettify" style=3D"color: #660;"><</=
span><span class=3D"styled-by-prettify" style=3D"color: #000;">T</span><spa=
n class=3D"styled-by-prettify" style=3D"color: #660;">*>(</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: #000;">p</span><span class=3D"st=
yled-by-prettify" style=3D"color: #660;">));</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;"><br></span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">}</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" style=3D"c=
olor: #660;">...</span><span class=3D"styled-by-prettify" style=3D"color: #=
000;"><br></span><span class=3D"styled-by-prettify" style=3D"color: #660;">=
};</span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></sp=
an></font></div></code></div></div><div><br></div><div><span class=3D"style=
d-by-prettify"><font color=3D"#000000">The trick is - it is a function witc=
h has all the information to do correct cast!</font></span></div><div><span=
class=3D"styled-by-prettify"><font color=3D"rgb(0,0,0)"><br></font></span>=
</div><div><span class=3D"styled-by-prettify"><font color=3D"rgb(0,0,0)">It=
is called like so</font></span></div><div><span class=3D"styled-by-prettif=
y"><font color=3D"rgb(0,0,0)"><br></font></span></div><span class=3D"styled=
-by-prettify"><font color=3D"rgb(0,0,0)"><div class=3D"prettyprint" style=
=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; background=
-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><font color=3D"rgb(0,0,0)" face=3D"Arial" style=3D"background-c=
olor: transparent;"><span class=3D"styled-by-prettify" style=3D"color: #000=
;">dcp</span><span class=3D"styled-by-prettify" style=3D"color: #660;">(</s=
pan><span class=3D"styled-by-prettify" style=3D"color: #000;">dcp </span><s=
pan class=3D"styled-by-prettify" style=3D"color: #008;">const</span><span c=
lass=3D"styled-by-prettify" style=3D"color: #660;">&</span><span class=
=3D"styled-by-prettify" style=3D"color: #000;"> other</span><span class=3D"=
styled-by-prettify" style=3D"color: #660;">)</span><span class=3D"styled-by=
-prettify" style=3D"color: #000;"> </span><span class=3D"styled-by-prettify=
" style=3D"color: #660;">:</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0t</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">(</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #000;">std</span><span class=3D"styled-by-prettify"=
style=3D"color: #660;">::</span><span class=3D"styled-by-prettify" style=
=3D"color: #000;">unique_ptr</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;"><</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #000;">T</span><span class=3D"styled-by-prettify" style=3D"color: #660=
;">>(</span><span class=3D"styled-by-prettify" style=3D"color: #000;">ot=
her</span><span class=3D"styled-by-prettify" style=3D"color: #660;">.</span=
><span class=3D"styled-by-prettify" style=3D"color: #000;">cast_p</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #660;"><</span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #000;">T</span><span class=3D"sty=
led-by-prettify" style=3D"color: #660;">>((</span><span class=3D"styled-=
by-prettify" style=3D"color: #000;">p </span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">=3D</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #000;"> other</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">.</span><span class=3D"styled-by-prettify" style=3D"color=
: #000;">c</span><span class=3D"styled-by-prettify" style=3D"color: #660;">=
(</span><span class=3D"styled-by-prettify" style=3D"color: #000;">other</sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;">.</span><span =
class=3D"styled-by-prettify" style=3D"color: #000;">p</span><span class=3D"=
styled-by-prettify" style=3D"color: #660;">))))),</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0c</sp=
an><span class=3D"styled-by-prettify" style=3D"color: #660;">(</span><span =
class=3D"styled-by-prettify" style=3D"color: #000;">other</span><span class=
=3D"styled-by-prettify" style=3D"color: #660;">.</span><span class=3D"style=
d-by-prettify" style=3D"color: #000;">c</span><span class=3D"styled-by-pret=
tify" style=3D"color: #660;">)</span><span class=3D"styled-by-prettify" sty=
le=3D"color: #000;"><br></span><span class=3D"styled-by-prettify" style=3D"=
color: #660;">{</span><span class=3D"styled-by-prettify" style=3D"color: #0=
00;"><br></span><span class=3D"styled-by-prettify" style=3D"color: #660;">}=
</span></font></div></code></div><div><br></div><div>As you can see we pres=
erve all information all the time to do a correct copy and cast and all is =
rooted to the original object (or copies of it)=C2=A0</div><div>as it is th=
e most derived one,=C2=A0we can possibly assign to.<br></div></font></span>=
<div><span class=3D"styled-by-prettify"><font color=3D"rgb(0,0,0)"><br></fo=
nt></span></div><div><span class=3D"styled-by-prettify"><font color=3D"rgb(=
0,0,0)">Here's a playable example</font></span></div><div><span class=
=3D"styled-by-prettify"><font color=3D"rgb(0,0,0)"><br></font></span></div>=
<div><span class=3D"styled-by-prettify"><font color=3D"rgb(0,0,0)">http://m=
elpon.org/wandbox/permlink/QQR0B96fdWDx1Pqr</font></span></div><div><span c=
lass=3D"styled-by-prettify"><font color=3D"rgb(0,0,0)"><br></font></span></=
div><div><span class=3D"styled-by-prettify"><font color=3D"rgb(0,0,0)"><br>=
</font></span></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/33a67392-1d55-40b4-ab15-22b91c8abc10%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/33a67392-1d55-40b4-ab15-22b91c8abc10=
%40isocpp.org</a>.<br />
------=_Part_1365_693685949.1477837274665--
------=_Part_1364_1969165227.1477837274665--
.
Author: mihailnajdenov@gmail.com
Date: Mon, 31 Oct 2016 04:13:32 -0700 (PDT)
Raw View
------=_Part_1071_549908646.1477912412171
Content-Type: multipart/alternative;
boundary="----=_Part_1072_197360784.1477912412172"
------=_Part_1072_197360784.1477912412172
Content-Type: text/plain; charset=UTF-8
Ok, I *think *I got the non-virtual (and aaaalmost non-allocating) version
working, based on joseph type erasure suggestion.
There are two key parts:
1) We completely remove the "smart casting" "up" to the original object. We
just store the original pointer unadjusted (alongside our main, possibly
adjusted from casting, T* pointer).
We do all copies on that unadjusted pointer and instead of "smart
casting" our T* up to the original - we simply reinterpret_cast the
unadjusted pointer in the copier.
template <typename T, T* (*Copier)(T*)>
void* type_erased_copy(void* p)
{
return Copier(reinterpret_cast<T*>(p));
}
// in the class
std::unique_ptr<T> t; //< main pointer, possibly adjusted by casting
void* p {}; //< original pointer, raw after polymorphic copy/user
supplied, without any casting!
....
p = other.c(other.p); //< copy the unadjusted one!
That was the easy part
2) The nightmare comes how to get the correctly casted main pointer back
from that raw, unadjusted pointer p!
Being void* not only kills any dynamic casting, but makes static_casting
compile and run, but return the wrong result!
For a class C : B1, B2 and B1 and B2 being virtually subclassing an A.
If you static_cast a C to a B2 it is OK, *but* if you static_casting a
*void** C it will return B1 !!!
In other words - to have correct casting you need to know both source and
destination type! You cant kill one of it with void and hope it will work.
But the problem is, because of type erasure, we can know at most two types
at the time and even this is only in the converting ctors.
When the type arrives in our converting ctor we not only must apply all of
its internal casting (new one might be a C, but holding a D) + the new
conversion (we are a B),
but also *save *the previous conversions chain (the one internal to C).
Exactly this requirement leads to the delegating_control_block chain - so
all conversions can be tracked to the original type, without any knowledge
of that type.
It seems this chaining is unavoidable.
It seems there can be no shortcuts, because we need the original type,
which can be erased many, many times -
D, assigned to C, assigned to B, assigned to A - a simple copy of A
requires the type of D!
The way I handle it in the non-virtual case is to hold a casting chain into
a vector (can be optimized with an array obviously).
Every time there is a conversion I add a new casting function.
Every time the class is copied, the casting chain is copied as well.
Every time there is a copy of the data - I apply all castings in the
original order.
template<class T, class U>
void* cast(void* p)
{
return static_cast<T*>(reinterpret_cast<U*>(p));
}
// in the class
using Func = void* (*)(void*);
std::vector<Func> casts;
void* perform_cast(void* p)
{
for(auto cast : casts)
p = cast(p);
return p;
}
template <typename U, typename V = std::enable_if_t<!std::is_same<T,
U>::value &&
std::is_convertible<U*, T*>::value>>
dcp(dcp<U> const& other)
{
p = other.c(other.p);
casts = other.casts; //< old chain
casts.push_back(cast<T, U>); //< add current conversion
t = std::unique_ptr<T>(reinterpret_cast<T*>(perform_cast(p))); //<
reinterpret safe here! (Edit: it can be part of perform_cast)
c = other.c;
}
Needless to say the casts themselves are insanely fast, but sadly still
need to be called trough the pointer.
I am not sure if any of the steps can be skipped, because, as said, we need
the types even if the cast is a noop (does not adjust the pointer).
Here's a playable example, comments are welcome.
http://melpon.org/wandbox/permlink/HfvrWyjfbR5cbY8Q
P.S.
OT: It is interesting to see if the function pointer casting rules can be
revisited, so the previous suggestion to use typed func pointers to become
valid, as it is the best option.
Mainly to be possible the function to return D* where the function pointer
expected an A* returned. This will eliminate the nasty chain!
Is it really invalid to call a A* (*)() pointer with a D* func() ?
(Assuming A is virtually subclassed by some B and so on.)
Can this be made possible ?!? After all the compiler has all the
information at call time AND the D to A conversion is implicit anyway!
--
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/35ff4fc1-98fa-4bad-9ebe-b806cfe80bb4%40isocpp.org.
------=_Part_1072_197360784.1477912412172
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Ok, I <i>think </i>I got the non-virtual (and aaaalmo=
st non-allocating)=C2=A0version working, based on <span class=3D"_username"=
><span class=3D"IVILX2C-D-a" style=3D"color: rgb(34, 34, 34);">joseph </spa=
n></span>type erasure suggestion.</div><div><br></div><div>There are two ke=
y parts:</div><div><br></div><div>1) We completely remove the "smart c=
asting" "up" to the original object. We just store the origi=
nal pointer unadjusted (alongside our main, possibly adjusted from casting,=
=C2=A0T*=C2=A0pointer).</div><div>We do all copies on that unadjusted point=
er and=C2=A0instead of "smart casting"=C2=A0our T* up to the orig=
inal=C2=A0 - we simply reinterpret_cast=C2=A0the unadjusted pointer=C2=A0in=
the copier.</div><code class=3D"prettyprint"><div><div class=3D"prettyprin=
t" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; ba=
ckground-color: rgb(250, 250, 250);"><div class=3D"subprettyprint"><font co=
lor=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transparent=
;"><span class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><sp=
an class=3D"styled-by-prettify" style=3D"color: #008;">template</span><span=
class=3D"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D=
"styled-by-prettify" style=3D"color: #660;"><</span><span class=3D"style=
d-by-prettify" style=3D"color: #008;">typename</span><span class=3D"styled-=
by-prettify" style=3D"color: #000;"> T</span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;">,</span><span class=3D"styled-by-prettify" styl=
e=3D"color: #000;"> T</span><span class=3D"styled-by-prettify" style=3D"col=
or: #660;">*</span><span class=3D"styled-by-prettify" style=3D"color: #000;=
"> </span><span class=3D"styled-by-prettify" style=3D"color: #660;">(*</spa=
n><span class=3D"styled-by-prettify" style=3D"color: #606;">Copier</span><s=
pan class=3D"styled-by-prettify" style=3D"color: #660;">)(</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #000;">T</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #660;">*)></span><span class=3D"styled-b=
y-prettify" style=3D"color: #000;"><br></span><span class=3D"styled-by-pret=
tify" style=3D"color: #008;">void</span><span class=3D"styled-by-prettify" =
style=3D"color: #660;">*</span><span class=3D"styled-by-prettify" style=3D"=
color: #000;"> type_erased_copy</span><span class=3D"styled-by-prettify" st=
yle=3D"color: #660;">(</span><span class=3D"styled-by-prettify" style=3D"co=
lor: #008;">void</span><span class=3D"styled-by-prettify" style=3D"color: #=
660;">*</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> p<=
/span><span class=3D"styled-by-prettify" style=3D"color: #660;">)</span><sp=
an class=3D"styled-by-prettify" style=3D"color: #000;"><br></span><span cla=
ss=3D"styled-by-prettify" style=3D"color: #660;">{</span><span class=3D"sty=
led-by-prettify" style=3D"color: #000;"><br>=C2=A0 =C2=A0 </span><span clas=
s=3D"styled-by-prettify" style=3D"color: #008;">return</span><span class=3D=
"styled-by-prettify" style=3D"color: #000;"> </span><span class=3D"styled-b=
y-prettify" style=3D"color: #606;">Copier</span><span class=3D"styled-by-pr=
ettify" style=3D"color: #660;">(</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #008;">reinterpret_cast</span><span class=3D"styled-by-prett=
ify" style=3D"color: #660;"><</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: #000;">T</span><span class=3D"styled-by-prettify" style=3D"c=
olor: #660;">*>(p</span><span class=3D"styled-by-prettify" style=3D"colo=
r: #660;">));</span><span class=3D"styled-by-prettify" style=3D"color: #000=
;"><br></span><span class=3D"styled-by-prettify" style=3D"color: #660;">}</=
span><span class=3D"styled-by-prettify" style=3D"color: #000;"><br><br>// i=
n the class<br><br>std::unique_ptr<T> t;=C2=A0=C2=A0 <font color=3D"#=
6aa84f">//<=C2=A0main pointer, possibly adjusted by casting<br></font>vo=
id* p {};=C2=A0 =C2=A0<font color=3D"#6aa84f">//<=C2=A0original pointer,=
raw after polymorphic copy/user supplied, without any casting!<br></font><=
br>...<br>p </span><span class=3D"styled-by-prettify" style=3D"color: #660;=
">=3D</span><span class=3D"styled-by-prettify" style=3D"color: #000;"> othe=
r</span><span class=3D"styled-by-prettify" style=3D"color: #660;">.</span><=
span class=3D"styled-by-prettify" style=3D"color: #000;">c</span><span clas=
s=3D"styled-by-prettify" style=3D"color: #660;">(</span><span class=3D"styl=
ed-by-prettify" style=3D"color: #000;">other</span><span class=3D"styled-by=
-prettify" style=3D"color: #660;">.</span><span class=3D"styled-by-prettify=
" style=3D"color: #000;">p</span><span class=3D"styled-by-prettify" style=
=3D"color: #660;">);<font color=3D"#000000"> </font><font color=3D"#6aa84f"=
>//< copy=C2=A0the unadjusted one!</font><br></span></font></div></div><=
/div></code><div class=3D"subprettyprint"><br></div><div><br></div><div>Tha=
t was the easy part</div><div><br></div><div>2) The nightmare comes how to =
get the correctly casted main pointer back from that raw, unadjusted pointe=
r p!</div><div><br></div><div>Being void* not only kills any dynamic castin=
g, but makes static_casting compile and run, but return the wrong result! <=
/div><div>For a class C : B1, B2 and B1 and B2 being virtually subclassing =
an A.</div><div>If you static_cast a C to a B2 it is OK, <b>but</b> if you =
static_casting a <b>void*</b> C it will return B1 !!!</div><div><br></div><=
div>In other words - to have correct casting you need to know both source a=
nd destination type! You cant kill one of it with void and hope it will wor=
k.</div><div><br></div><div>But the problem is, because of type erasure, we=
can know at most two types at the time and even this is only in the conver=
ting ctors.</div><div>When the type arrives in our converting ctor we not o=
nly must apply all of its internal casting (new one might be a C, but holdi=
ng a D)=C2=A0+ the new conversion (we are a B),</div><div>but also=C2=A0<b>=
save </b>the previous conversions chain (the one internal to C). </div><div=
><br></div><div>Exactly this requirement leads to the delegating_control_bl=
ock chain - so all conversions can be tracked to the original type, without=
any knowledge of that type.</div><div><br></div><div>It seems this chainin=
g is unavoidable. </div><div>It seems there can be no shortcuts, because we=
need the original type, which can be erased many, many times - </div><div>=
D, assigned to C, assigned to=C2=A0B, assigned to A -=C2=A0 a simple copy o=
f A requires the type of D!</div><div><br></div><div>The way I handle it in=
the non-virtual case is to hold a casting chain into a vector (can be opti=
mized with an array obviously).</div><div><br></div><div>Every time there i=
s a conversion I add a new casting function.</div><div>Every time the class=
is copied, the casting chain is copied as well. </div><div>Every time ther=
e is a copy of the data=C2=A0- I apply all castings in the original order.<=
/div><div><br></div><div><br></div><div class=3D"prettyprint" style=3D"bord=
er: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color: =
rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettypri=
nt"><span class=3D"styled-by-prettify" style=3D"color: #606;"><font color=
=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color: transparent;">=
template<class T, class U><br>void* cast(void* p)<br>{<br>=C2=A0 retu=
rn static_cast<T*>(reinterpret_cast<U*>(p));<br>}<br><br>// in =
the=C2=A0class<br><br>=C2=A0=C2=A0=C2=A0 using Func =3D void* (*)(void*);<b=
r><br>=C2=A0=C2=A0=C2=A0 std::vector<Func> casts;<br><br>=C2=A0=C2=A0=
=C2=A0 void* perform_cast(void* p)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for(auto cast : casts)<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 p =3D cast(p);<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return p;<br>=C2=A0=C2=A0=C2=A0 }<br><=
br>=C2=A0=C2=A0=C2=A0 template <typename U, typename V =3D std::enable_i=
f_t<!std::is_same<T, U>::value &&<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 std::is_convertible<U*, T*>::value>><br>=C2=A0=C2=A0=C2=A0=
=C2=A0dcp(dcp<U> const& other)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 p =3D other.c(other.p);<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 casts =3D other.casts;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0//< old ch=
ain=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 casts.pus=
h_back(cast<T, U>);=C2=A0=C2=A0 //< add current conversion<br>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 t =3D std::unique_ptr<T>(reinterpret_c=
ast<T*>(perform_cast(p))); //< reinterpret safe here! (Edit: it ca=
n be part of perform_cast)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 c =3D other.c;=
<br>=C2=A0=C2=A0=C2=A0 }<br></font></span><span class=3D"styled-by-prettify=
" style=3D"color: #660;"></span></div></code></div><div><br></div><div>Need=
less to say the casts themselves are insanely fast, but sadly still need to=
be called trough the pointer.</div><div><br></div><div>I am not sure if an=
y of the steps can be skipped, because, as said, we need the types even if =
the cast is a=C2=A0noop (does not adjust the pointer).<br></div><div><br></=
div><div>Here's=C2=A0a playable example, comments are welcome.</div><di=
v><br></div><div>http://melpon.org/wandbox/permlink/HfvrWyjfbR5cbY8Q</div><=
div><br></div><div><br></div><div>P.S. </div><div>OT:=C2=A0It is interestin=
g to see if the function pointer casting rules can be revisited, so the pre=
vious suggestion to use typed func pointers=C2=A0to=C2=A0become valid, as i=
t is the best option. </div><div>Mainly to be possible the function to retu=
rn D*=C2=A0where the function pointer expected an A* returned. This will el=
iminate the nasty chain! </div><div><br></div><div>Is it really invalid to =
call a A* (*)()=C2=A0pointer with a D* func() ? </div><div>(Assuming=C2=A0A=
is virtually subclassed by some B=C2=A0and so on.)=C2=A0</div><div><br></d=
iv><div>Can this be made possible ?!? After all the compiler has all the in=
formation at call time AND the D to A conversion is implicit anyway!</div><=
div><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/35ff4fc1-98fa-4bad-9ebe-b806cfe80bb4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/35ff4fc1-98fa-4bad-9ebe-b806cfe80bb4=
%40isocpp.org</a>.<br />
------=_Part_1072_197360784.1477912412172--
------=_Part_1071_549908646.1477912412171--
.
Author: Jonathan Coe <jbcoe@me.com>
Date: Mon, 31 Oct 2016 11:28:04 +0000
Raw View
--001a113c2a486c1f43054027806b
Content-Type: text/plain; charset=UTF-8
On 31 October 2016 at 11:13, <mihailnajdenov@gmail.com> wrote:
> Ok, I *think *I got the non-virtual (and aaaalmost
> non-allocating) version working, based on joseph type erasure suggestion.
>
> There are two key parts:
>
> 1) We completely remove the "smart casting" "up" to the original object.
> We just store the original pointer unadjusted (alongside our main, possibly
> adjusted from casting, T* pointer).
> We do all copies on that unadjusted pointer and instead of "smart
> casting" our T* up to the original - we simply reinterpret_cast the
> unadjusted pointer in the copier.
>
> template <typename T, T* (*Copier)(T*)>
> void* type_erased_copy(void* p)
> {
> return Copier(reinterpret_cast<T*>(p));
> }
>
> // in the class
>
> std::unique_ptr<T> t; //< main pointer, possibly adjusted by casting
> void* p {}; //< original pointer, raw after polymorphic copy/user
> supplied, without any casting!
>
> ...
> p = other.c(other.p); //< copy the unadjusted one!
>
>
> That was the easy part
>
> 2) The nightmare comes how to get the correctly casted main pointer back
> from that raw, unadjusted pointer p!
>
> Being void* not only kills any dynamic casting, but makes static_casting
> compile and run, but return the wrong result!
> For a class C : B1, B2 and B1 and B2 being virtually subclassing an A.
> If you static_cast a C to a B2 it is OK, *but* if you static_casting a
> *void** C it will return B1 !!!
>
> In other words - to have correct casting you need to know both source and
> destination type! You cant kill one of it with void and hope it will work.
>
> But the problem is, because of type erasure, we can know at most two types
> at the time and even this is only in the converting ctors.
> When the type arrives in our converting ctor we not only must apply all of
> its internal casting (new one might be a C, but holding a D) + the new
> conversion (we are a B),
> but also *save *the previous conversions chain (the one internal to C).
>
> Exactly this requirement leads to the delegating_control_block chain - so
> all conversions can be tracked to the original type, without any knowledge
> of that type.
>
> It seems this chaining is unavoidable.
> It seems there can be no shortcuts, because we need the original type,
> which can be erased many, many times -
> D, assigned to C, assigned to B, assigned to A - a simple copy of A
> requires the type of D!
>
> The way I handle it in the non-virtual case is to hold a casting chain
> into a vector (can be optimized with an array obviously).
>
> Every time there is a conversion I add a new casting function.
> Every time the class is copied, the casting chain is copied as well.
> Every time there is a copy of the data - I apply all castings in the
> original order.
>
>
> template<class T, class U>
> void* cast(void* p)
> {
> return static_cast<T*>(reinterpret_cast<U*>(p));
> }
>
> // in the class
>
> using Func = void* (*)(void*);
>
> std::vector<Func> casts;
>
> void* perform_cast(void* p)
> {
> for(auto cast : casts)
> p = cast(p);
> return p;
> }
>
> template <typename U, typename V = std::enable_if_t<!std::is_same<T,
> U>::value &&
> std::is_convertible<U*, T*>::value>>
> dcp(dcp<U> const& other)
> {
> p = other.c(other.p);
> casts = other.casts; //< old chain
> casts.push_back(cast<T, U>); //< add current conversion
>
> t = std::unique_ptr<T>(reinterpret_cast<T*>(perform_cast(p))); //<
> reinterpret safe here! (Edit: it can be part of perform_cast)
> c = other.c;
> }
>
> Needless to say the casts themselves are insanely fast, but sadly still
> need to be called trough the pointer.
>
> I am not sure if any of the steps can be skipped, because, as said, we
> need the types even if the cast is a noop (does not adjust the pointer).
>
> Here's a playable example, comments are welcome.
>
> http://melpon.org/wandbox/permlink/HfvrWyjfbR5cbY8Q
>
>
> P.S.
> OT: It is interesting to see if the function pointer casting rules can be
> revisited, so the previous suggestion to use typed func pointers to become
> valid, as it is the best option.
> Mainly to be possible the function to return D* where the function pointer
> expected an A* returned. This will eliminate the nasty chain!
>
> Is it really invalid to call a A* (*)() pointer with a D* func() ?
> (Assuming A is virtually subclassed by some B and so on.)
>
> Can this be made possible ?!? After all the compiler has all the
> information at call time AND the D to A conversion is implicit anyway!
>
>
If you can submit this as a PR against the reference implementation I'd be
happy to incorporate it. It would be good to get code in the same place.
https://github.com/jbcoe/indirect
> --
> 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/35ff4fc1-98fa-4bad-
> 9ebe-b806cfe80bb4%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/35ff4fc1-98fa-4bad-9ebe-b806cfe80bb4%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CAAbBDD8k3KXbd%2B%3DMhogjAz7ZRpNdi8hqfhyx%3D6vRMCMeeAWiMg%40mail.gmail.com.
--001a113c2a486c1f43054027806b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On 31 October 2016 at 11:13, <span dir=3D"ltr"><<a href=3D"mailto:m=
ihailnajdenov@gmail.com" target=3D"_blank">mihailnajdenov@gmail.com</a>>=
</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-=
left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div>Ok, I <i>think </i=
>I got the non-virtual (and aaaalmost non-allocating)=C2=A0version working,=
based on <span class=3D"gmail-m_2717427920177359702_username"><span class=
=3D"gmail-m_2717427920177359702IVILX2C-D-a" style=3D"color:rgb(34,34,34)">j=
oseph </span></span>type erasure suggestion.</div><div><br></div><div>There=
are two key parts:</div><div><br></div><div>1) We completely remove the &q=
uot;smart casting" "up" to the original object. We just stor=
e the original pointer unadjusted (alongside our main, possibly adjusted fr=
om casting,=C2=A0T*=C2=A0pointer).</div><div>We do all copies on that unadj=
usted pointer and=C2=A0instead of "smart casting"=C2=A0our T* up =
to the original=C2=A0 - we simply reinterpret_cast=C2=A0the unadjusted poin=
ter=C2=A0in the copier.</div><code class=3D"gmail-m_2717427920177359702pret=
typrint"><div><div class=3D"gmail-m_2717427920177359702prettyprint" style=
=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color=
:rgb(250,250,250)"><div class=3D"gmail-m_2717427920177359702subprettyprint"=
><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color:tra=
nsparent"><span class=3D"gmail-m_2717427920177359702styled-by-prettify" sty=
le=3D"color:rgb(0,0,0)"><br></span><span class=3D"gmail-m_27174279201773597=
02styled-by-prettify" style=3D"color:rgb(0,0,136)">template</span><span cla=
ss=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:rgb(0,0=
,0)"> </span><span class=3D"gmail-m_2717427920177359702styled-by-prettify" =
style=3D"color:rgb(102,102,0)"><</span><span class=3D"gmail-m_2717427920=
177359702styled-by-prettify" style=3D"color:rgb(0,0,136)">typename</span><s=
pan class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:=
rgb(0,0,0)"> T</span><span class=3D"gmail-m_2717427920177359702styled-by-pr=
ettify" style=3D"color:rgb(102,102,0)">,</span><span class=3D"gmail-m_27174=
27920177359702styled-by-prettify" style=3D"color:rgb(0,0,0)"> T</span><span=
class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:rgb=
(102,102,0)">*</span><span class=3D"gmail-m_2717427920177359702styled-by-pr=
ettify" style=3D"color:rgb(0,0,0)"> </span><span class=3D"gmail-m_271742792=
0177359702styled-by-prettify" style=3D"color:rgb(102,102,0)">(*</span><span=
class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:rgb=
(102,0,102)">Copier</span><span class=3D"gmail-m_2717427920177359702styled-=
by-prettify" style=3D"color:rgb(102,102,0)">)(</span><span class=3D"gmail-m=
_2717427920177359702styled-by-prettify" style=3D"color:rgb(0,0,0)">T</span>=
<span class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"colo=
r:rgb(102,102,0)">*)></span><span class=3D"gmail-m_2717427920177359702st=
yled-by-prettify" style=3D"color:rgb(0,0,0)"><br></span><span class=3D"gmai=
l-m_2717427920177359702styled-by-prettify" style=3D"color:rgb(0,0,136)">voi=
d</span><span class=3D"gmail-m_2717427920177359702styled-by-prettify" style=
=3D"color:rgb(102,102,0)">*</span><span class=3D"gmail-m_271742792017735970=
2styled-by-prettify" style=3D"color:rgb(0,0,0)"> type_erased_copy</span><sp=
an class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:r=
gb(102,102,0)">(</span><span class=3D"gmail-m_2717427920177359702styled-by-=
prettify" style=3D"color:rgb(0,0,136)">void</span><span class=3D"gmail-m_27=
17427920177359702styled-by-prettify" style=3D"color:rgb(102,102,0)">*</span=
><span class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"col=
or:rgb(0,0,0)"> p</span><span class=3D"gmail-m_2717427920177359702styled-by=
-prettify" style=3D"color:rgb(102,102,0)">)</span><span class=3D"gmail-m_27=
17427920177359702styled-by-prettify" style=3D"color:rgb(0,0,0)"><br></span>=
<span class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"colo=
r:rgb(102,102,0)">{</span><span class=3D"gmail-m_2717427920177359702styled-=
by-prettify" style=3D"color:rgb(0,0,0)"><br>=C2=A0 =C2=A0 </span><span clas=
s=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:rgb(0,0,=
136)">return</span><span class=3D"gmail-m_2717427920177359702styled-by-pret=
tify" style=3D"color:rgb(0,0,0)"> </span><span class=3D"gmail-m_27174279201=
77359702styled-by-prettify" style=3D"color:rgb(102,0,102)">Copier</span><sp=
an class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:r=
gb(102,102,0)">(</span><span class=3D"gmail-m_2717427920177359702styled-by-=
prettify" style=3D"color:rgb(0,0,136)">reinterpret_cast</span><span class=
=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:rgb(102,1=
02,0)"><</span><span class=3D"gmail-m_2717427920177359702styled-by-prett=
ify" style=3D"color:rgb(0,0,0)">T</span><span class=3D"gmail-m_271742792017=
7359702styled-by-prettify" style=3D"color:rgb(102,102,0)">*>(p</span><sp=
an class=3D"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:r=
gb(102,102,0)">)<wbr>);</span><span class=3D"gmail-m_2717427920177359702sty=
led-by-prettify" style=3D"color:rgb(0,0,0)"><br></span><span class=3D"gmail=
-m_2717427920177359702styled-by-prettify" style=3D"color:rgb(102,102,0)">}<=
/span><span class=3D"gmail-m_2717427920177359702styled-by-prettify" style=
=3D"color:rgb(0,0,0)"><br><br>// in the class<br><br>std::unique_ptr<T&g=
t; t;=C2=A0=C2=A0 <font color=3D"#6aa84f">//<=C2=A0main pointer, possibl=
y adjusted by casting<br></font>void* p {};=C2=A0 =C2=A0<font color=3D"#6aa=
84f">//<=C2=A0original pointer, raw after polymorphic copy/user supplied=
, without any casting!<br></font><br>...<br>p </span><span class=3D"gmail-m=
_2717427920177359702styled-by-prettify" style=3D"color:rgb(102,102,0)">=3D<=
/span><span class=3D"gmail-m_2717427920177359702styled-by-prettify" style=
=3D"color:rgb(0,0,0)"> other</span><span class=3D"gmail-m_27174279201773597=
02styled-by-prettify" style=3D"color:rgb(102,102,0)">.</span><span class=3D=
"gmail-m_2717427920177359702styled-by-prettify" style=3D"color:rgb(0,0,0)">=
c</span><span class=3D"gmail-m_2717427920177359702styled-by-prettify" style=
=3D"color:rgb(102,102,0)">(</span><span class=3D"gmail-m_271742792017735970=
2styled-by-prettify" style=3D"color:rgb(0,0,0)">other</span><span class=3D"=
gmail-m_2717427920177359702styled-by-prettify" style=3D"color:rgb(102,102,0=
)">.</span><span class=3D"gmail-m_2717427920177359702styled-by-prettify" st=
yle=3D"color:rgb(0,0,0)">p</span><span class=3D"gmail-m_2717427920177359702=
styled-by-prettify" style=3D"color:rgb(102,102,0)">);<font color=3D"#000000=
"> </font><font color=3D"#6aa84f">//< copy=C2=A0the unadjusted one!</fon=
t><br></span></font></div></div></div></code><div class=3D"gmail-m_27174279=
20177359702subprettyprint"><br></div><div><br></div><div>That was the easy =
part</div><div><br></div><div>2) The nightmare comes how to get the correct=
ly casted main pointer back from that raw, unadjusted pointer p!</div><div>=
<br></div><div>Being void* not only kills any dynamic casting, but makes st=
atic_casting compile and run, but return the wrong result! </div><div>For a=
class C : B1, B2 and B1 and B2 being virtually subclassing an A.</div><div=
>If you static_cast a C to a B2 it is OK, <b>but</b> if you static_casting =
a <b>void*</b> C it will return B1 !!!</div><div><br></div><div>In other wo=
rds - to have correct casting you need to know both source and destination =
type! You cant kill one of it with void and hope it will work.</div><div><b=
r></div><div>But the problem is, because of type erasure, we can know at mo=
st two types at the time and even this is only in the converting ctors.</di=
v><div>When the type arrives in our converting ctor we not only must apply =
all of its internal casting (new one might be a C, but holding a D)=C2=A0+ =
the new conversion (we are a B),</div><div>but also=C2=A0<b>save </b>the pr=
evious conversions chain (the one internal to C). </div><div><br></div><div=
>Exactly this requirement leads to the delegating_control_block chain - so =
all conversions can be tracked to the original type, without any knowledge =
of that type.</div><div><br></div><div>It seems this chaining is unavoidabl=
e. </div><div>It seems there can be no shortcuts, because we need the origi=
nal type, which can be erased many, many times - </div><div>D, assigned to =
C, assigned to=C2=A0B, assigned to A -=C2=A0 a simple copy of A requires th=
e type of D!</div><div><br></div><div>The way I handle it in the non-virtua=
l case is to hold a casting chain into a vector (can be optimized with an a=
rray obviously).</div><div><br></div><div>Every time there is a conversion =
I add a new casting function.</div><div>Every time the class is copied, the=
casting chain is copied as well. </div><div>Every time there is a copy of =
the data=C2=A0- I apply all castings in the original order.</div><div><br><=
/div><div><br></div><div class=3D"gmail-m_2717427920177359702prettyprint" s=
tyle=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-c=
olor:rgb(250,250,250)"><code class=3D"gmail-m_2717427920177359702prettyprin=
t"><div class=3D"gmail-m_2717427920177359702subprettyprint"><span class=3D"=
gmail-m_2717427920177359702styled-by-prettify" style=3D"color:rgb(102,0,102=
)"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color:t=
ransparent">template<class T, class U><br>void* cast(void* p)<br>{<br=
>=C2=A0 return static_cast<T*>(reinterpret_<wbr>cast<U*>(p));<b=
r>}<br><br>// in the=C2=A0class<br><br>=C2=A0=C2=A0=C2=A0 using Func =3D vo=
id* (*)(void*);<br><br>=C2=A0=C2=A0=C2=A0 std::vector<Func> casts;<br=
><br>=C2=A0=C2=A0=C2=A0 void* perform_cast(void* p)<br>=C2=A0=C2=A0=C2=A0 {=
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for(auto cast : casts)<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 p =3D ca=
st(p);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return p;<span class=
=3D"gmail-"><br>=C2=A0=C2=A0=C2=A0 }<br><br>=C2=A0=C2=A0=C2=A0 template <=
;typename U, typename V =3D std::enable_if_t<!std::is_<wbr>same<T, U&=
gt;::value &&<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::is_convertible<=
U*, T*>::value>><br></span>=C2=A0=C2=A0=C2=A0=C2=A0dcp(dcp<U>=
; const& other)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 p =3D other.c(other.p);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 casts =3D oth=
er.casts;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0//< old chain=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 casts.push_back(cast<T, U&g=
t;);=C2=A0=C2=A0 //< add current conversion<br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 t =3D std::unique_ptr<T>(<wbr>reinterpret_cast<T*>(pe=
rform_<wbr>cast(p))); //< reinterpret safe here! (Edit: it can be part o=
f perform_cast)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 c =3D other.c;<br>=C2=A0=
=C2=A0=C2=A0 }<br></font></span><span class=3D"gmail-m_2717427920177359702s=
tyled-by-prettify" style=3D"color:rgb(102,102,0)"></span></div></code></div=
><div><br></div><div>Needless to say the casts themselves are insanely fast=
, but sadly still need to be called trough the pointer.</div><div><br></div=
><div>I am not sure if any of the steps can be skipped, because, as said, w=
e need the types even if the cast is a=C2=A0noop (does not adjust the point=
er).<br></div><div><br></div><div>Here's=C2=A0a playable example, comme=
nts are welcome.</div><div><br></div><div><a href=3D"http://melpon.org/wand=
box/permlink/HfvrWyjfbR5cbY8Q" target=3D"_blank">http://melpon.org/wandbox/=
<wbr>permlink/HfvrWyjfbR5cbY8Q</a></div><div><br></div><div><br></div><div>=
P.S. </div><div>OT:=C2=A0It is interesting to see if the function pointer c=
asting rules can be revisited, so the previous suggestion to use typed func=
pointers=C2=A0to=C2=A0become valid, as it is the best option. </div><div>M=
ainly to be possible the function to return D*=C2=A0where the function poin=
ter expected an A* returned. This will eliminate the nasty chain! </div><di=
v><br></div><div>Is it really invalid to call a A* (*)()=C2=A0pointer with =
a D* func() ? </div><div>(Assuming=C2=A0A is virtually subclassed by some B=
=C2=A0and so on.)=C2=A0</div><div><br></div><div>Can this be made possible =
?!? After all the compiler has all the information at call time AND the D t=
o A conversion is implicit anyway!</div><div><br></div></div></blockquote><=
div><br></div><div>If you can submit this as a PR against the reference imp=
lementation I'd be happy to incorporate it. It would be good to get cod=
e in the same place.</div><div><br></div><div><a href=3D"https://github.com=
/jbcoe/indirect">https://github.com/jbcoe/indirect</a><br></div><blockquote=
class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:=
1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left=
:1ex"><div dir=3D"ltr"><div></div></div><span class=3D"gmail-">
<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" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>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></span>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/35ff4fc1-98fa-4bad-9ebe-b806cfe80bb4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/35ff=
4fc1-98fa-4bad-<wbr>9ebe-b806cfe80bb4%40isocpp.org</a><wbr>.<br>
</blockquote></div><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/CAAbBDD8k3KXbd%2B%3DMhogjAz7ZRpNdi8hq=
fhyx%3D6vRMCMeeAWiMg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAAbBDD8k3K=
Xbd%2B%3DMhogjAz7ZRpNdi8hqfhyx%3D6vRMCMeeAWiMg%40mail.gmail.com</a>.<br />
--001a113c2a486c1f43054027806b--
.
Author: mihailnajdenov@gmail.com
Date: Tue, 1 Nov 2016 03:38:38 -0700 (PDT)
Raw View
------=_Part_1365_1490227835.1477996718455
Content-Type: multipart/alternative;
boundary="----=_Part_1366_752754901.1477996718456"
------=_Part_1366_752754901.1477996718456
Content-Type: text/plain; charset=UTF-8
On Monday, October 31, 2016 at 1:28:07 PM UTC+2, Jonathan Coe wrote:
>
> ...
>>
>
> If you can submit this as a PR against the reference implementation I'd be
> happy to incorporate it. It would be good to get code in the same place.
>
> https://github.com/jbcoe/indirect
>
>> ...
>>
>
>
Ok, here's the complete proof-of-concept implementation, with support of
functor coper and deleter
These turned out to be trivial if we use a std::any to store the functors
and a stub to cast it to the original type.
Best part is - std::any is already SOO, so no new allocations for
most-if-not-all real-world cases. Needless to say, no virtual calls also.
http://melpon.org/wandbox/permlink/03REStMLgjQ40svU
As for pushing to the indirect, I will look into it. I have no experience
with github, and I don't even know what PR is (I guess R is for request).
I will look into it, though, in the coming days.
--
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/addade83-ada9-49c4-a1be-a6e1990162e9%40isocpp.org.
------=_Part_1366_752754901.1477996718456
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, October 31, 2016 at 1:28:07 PM UTC+2, J=
onathan Coe wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(2=
04,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div=
>...<br></div></div></blockquote><div><br></div><div>If you can submit this=
as a PR against the reference implementation I'd be happy to incorpora=
te it. It would be good to get code in the same place.</div><div><br></div>=
<div><a onmousedown=3D"this.href=3D'https://www.google.com/url?q\x3dhtt=
ps%3A%2F%2Fgithub.com%2Fjbcoe%2Findirect\x26sa\x3dD\x26sntz\x3d1\x26usg\x3d=
AFQjCNEmhBT9d5pp-SIzW1iBUZg13QovxQ';return true;" onclick=3D"this.href=
=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjbcoe%2F=
indirect\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEmhBT9d5pp-SIzW1iBUZg13Qov=
xQ';return true;" href=3D"https://github.com/jbcoe/indirect" target=3D"=
_blank" rel=3D"nofollow">https://github.com/jbcoe/<wbr>indirect</a><br></di=
v><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;borde=
r-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid=
;padding-left:1ex"><div dir=3D"ltr"><div></div></div><span>
<p></p>
....</span><br>
</blockquote></div><br></div></div></blockquote><div><br></div><div>Ok, her=
e's the complete=C2=A0proof-of-concept implementation, with support of =
functor coper and deleter </div><div><br></div><div><div>These turned out t=
o be trivial if we use a std::any to store the functors and a stub to cast =
it to the original type.</div><div>Best part is - std::any is already SOO, =
so no new allocations for most-if-not-all real-world cases. Needless to say=
, no virtual calls also.</div><div><br></div></div><div>http://melpon.org/w=
andbox/permlink/03REStMLgjQ40svU</div><div><br></div><div>As for pushing to=
the indirect, I will look into it. I have no experience with github, and I=
don't even know what PR is=C2=A0(I guess R is for request).</div><div>=
I will look into it, though, in the coming days.</div><div><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/addade83-ada9-49c4-a1be-a6e1990162e9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/addade83-ada9-49c4-a1be-a6e1990162e9=
%40isocpp.org</a>.<br />
------=_Part_1366_752754901.1477996718456--
------=_Part_1365_1490227835.1477996718455--
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 16:54:24 +0800
Raw View
--001a113ac244535a47054061b430
Content-Type: text/plain; charset=UTF-8
This seems like a promising approach. I didn't think of type erasing the
casts as well. Nicely done!
However, one thing that hasn't sat right with me is the erasure of the
types of the deleter and copier. Of course, there may be an argument for
the added flexibility if the control block already exists, like in
shared_ptr. However, now that we have a control block-less design, I think
it makes sense to have the deleter and copier types fixed in the wrapper
type.
But how to make this work with the type erasure of the managed object? With
unique_ptr, copying/moving the deleter to a unique_ptr with another type of
deleter works fine because you can pass the managed object to anything that
can take it. However, with type erasure we have to hardcode the type of the
deleter and copier into the type-erased interface. All compatible wrappers
would need to share the same deleter and copier types. This would actually
be possible with something like this:
struct default_polymorphic_deleter
{
template <typename T>
void operator()(T* t) const
{
delete t;
}
};
This doesn't seem like such a bad thing when you think about how deleters
and copiers are likely to be used. It makes sense that the same deleter and
copier would be used for an inheritance hierarchy of types.
This means we have zero heap allocation for all deleters and copiers, and
the deleter and copier will usually cost us only the size of a function
pointer each (for type erased invocation) thanks to the empty base class
optimization. Then we have zero heap allocation (and dynamic dispatches)
for type erasure and we can implement reset and release problem free,
thanks to your technique.
On 1 Nov 2016 18:38, <mihailnajdenov@gmail.com> wrote:
>
>
> On Monday, October 31, 2016 at 1:28:07 PM UTC+2, Jonathan Coe wrote:
>>
>> ...
>>>
>>
>> If you can submit this as a PR against the reference implementation I'd
>> be happy to incorporate it. It would be good to get code in the same place.
>>
>> https://github.com/jbcoe/indirect
>>
>>> ...
>>>
>>
>>
> Ok, here's the complete proof-of-concept implementation, with support of
> functor coper and deleter
>
> These turned out to be trivial if we use a std::any to store the functors
> and a stub to cast it to the original type.
> Best part is - std::any is already SOO, so no new allocations for
> most-if-not-all real-world cases. Needless to say, no virtual calls also.
>
> http://melpon.org/wandbox/permlink/03REStMLgjQ40svU
>
> As for pushing to the indirect, I will look into it. I have no experience
> with github, and I don't even know what PR is (I guess R is for request).
> I will look into it, though, in the coming days.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this topic, visit https://groups.google.com/a/
> isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe.
> To unsubscribe from this group and all its topics, 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/addade83-ada9-49c4-
> a1be-a6e1990162e9%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/addade83-ada9-49c4-a1be-a6e1990162e9%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CAHocnE_C8vs%2BxokoBO9JB3iL4hnwCnQeXfKtepLu81b_zmBK%3DA%40mail.gmail.com.
--001a113ac244535a47054061b430
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">This seems like a promising approach. I didn't think of =
type erasing the casts as well. Nicely done!</p>
<p dir=3D"ltr">However, one thing that hasn't sat right with me is the =
erasure of the types of the deleter and copier. Of course, there may be an =
argument for the added flexibility if the control block already exists, lik=
e in shared_ptr. However, now that we have a control block-less design, I t=
hink it makes sense to have the deleter and copier types fixed in the wrapp=
er type.</p>
<p dir=3D"ltr">But how to make this work with the type erasure of the manag=
ed object? With unique_ptr, copying/moving the deleter to a unique_ptr with=
another type of deleter works fine because you can pass the managed object=
to anything that can take it. However, with type erasure we have to hardco=
de the type of the deleter and copier into the type-erased interface. All c=
ompatible wrappers would need to share the same deleter and copier types. T=
his would actually be possible with something like this:</p>
<p dir=3D"ltr">struct default_polymorphic_deleter<br>
{<br>
=C2=A0=C2=A0=C2=A0 template <typename T><br>
=C2=A0=C2=A0=C2=A0 void operator()(T* t) const<br>
=C2=A0=C2=A0=C2=A0 {<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 delete t;<br>
=C2=A0=C2=A0=C2=A0 }<br>
};</p>
<p dir=3D"ltr">This doesn't seem like such a bad thing when you think a=
bout how deleters and copiers are likely to be used. It makes sense that th=
e same deleter and copier would be used for an inheritance hierarchy of typ=
es.</p>
<p dir=3D"ltr">This means we have zero heap allocation for all deleters and=
copiers, and the deleter and copier will usually cost us only the size of =
a function pointer each (for type erased invocation) thanks to the empty ba=
se class optimization. Then we have zero heap allocation (and dynamic dispa=
tches) for type erasure and we can implement reset and release problem free=
, thanks to your technique.</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 1 Nov 2016 18:=
38, <<a href=3D"mailto:mihailnajdenov@gmail.com">mihailnajdenov@gmail.c=
om</a>> wrote:<br type=3D"attribution"><blockquote class=3D"gmail_quote"=
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr"><br><br>On Monday, October 31, 2016 at 1:28:07 PM UTC+2, Jon=
athan Coe 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"><d=
iv><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,=
204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div>...<br=
></div></div></blockquote><div><br></div><div>If you can submit this as a P=
R against the reference implementation I'd be happy to incorporate it. =
It would be good to get code in the same place.</div><div><br></div><div><a=
href=3D"https://github.com/jbcoe/indirect" rel=3D"nofollow" target=3D"_bla=
nk">https://github.com/jbcoe/indir<wbr>ect</a><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;bo=
rder-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">=
<div dir=3D"ltr"><div></div></div><span>
<p></p>
....</span><br>
</blockquote></div><br></div></div></blockquote><div><br></div><div>Ok, her=
e's the complete=C2=A0proof-of-concept implementation, with support of =
functor coper and deleter </div><div><br></div><div><div>These turned out t=
o be trivial if we use a std::any to store the functors and a stub to cast =
it to the original type.</div><div>Best part is - std::any is already SOO, =
so no new allocations for most-if-not-all real-world cases. Needless to say=
, no virtual calls also.</div><div><br></div></div><div><a href=3D"http://m=
elpon.org/wandbox/permlink/03REStMLgjQ40svU" target=3D"_blank">http://melpo=
n.org/wandbox/<wbr>permlink/03REStMLgjQ40svU</a></div><div><br></div><div>A=
s for pushing to the indirect, I will look into it. I have no experience wi=
th github, and I don't even know what PR is=C2=A0(I guess R is for requ=
est).</div><div>I will look into it, though, in the coming days.</div><div>=
<br></div></div>
<p></p>
-- <br>
You received this message because you are subscribed to a topic in the Goog=
le Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe" target=3D"_blan=
k">https://groups.google.com/a/<wbr>isocpp.org/d/topic/std-<wbr>proposals/E=
VA-oFQXpKo/<wbr>unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_blank">std-prop=
osals+unsubscribe@<wbr>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/addade83-ada9-49c4-a1be-a6e1990162e9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/adda=
de83-ada9-49c4-<wbr>a1be-a6e1990162e9%40isocpp.org</a><wbr>.<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/CAHocnE_C8vs%2BxokoBO9JB3iL4hnwCnQeXf=
KtepLu81b_zmBK%3DA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE_C8vs%=
2BxokoBO9JB3iL4hnwCnQeXfKtepLu81b_zmBK%3DA%40mail.gmail.com</a>.<br />
--001a113ac244535a47054061b430--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Nov 2016 11:04:51 +0200
Raw View
On 3 November 2016 at 10:54, Joseph Thomson <joseph.thomson@gmail.com> wrote:
> However, one thing that hasn't sat right with me is the erasure of the types
> of the deleter and copier. Of course, there may be an argument for the added
> flexibility if the control block already exists, like in shared_ptr.
> However, now that we have a control block-less design, I think it makes
> sense to have the deleter and copier types fixed in the wrapper type.
If you have an indirect<Base> and you assign an indirect<Derived1> to
it, and again assign
an indirect<Derived2> to it, fixing the copier/deleter will stop the
correct cloning and deletion of the target.
--
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/CAFk2RUZbR9yjJXYXDMx-HwRc8m282-xGk0Tn%2BwCmi3vBv0m_XA%40mail.gmail.com.
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 17:22:21 +0800
Raw View
--001a1140b62449da720540621818
Content-Type: text/plain; charset=UTF-8
Sorry, I'm not sure what you mean. The deleter and copier can still be
copied and moved around with the managed object; it's just that all
compatible indirect types must share the same types of deleter and copier.
On 3 Nov 2016 17:04, "Ville Voutilainen" <ville.voutilainen@gmail.com>
wrote:
> On 3 November 2016 at 10:54, Joseph Thomson <joseph.thomson@gmail.com>
> wrote:
> > However, one thing that hasn't sat right with me is the erasure of the
> types
> > of the deleter and copier. Of course, there may be an argument for the
> added
> > flexibility if the control block already exists, like in shared_ptr.
> > However, now that we have a control block-less design, I think it makes
> > sense to have the deleter and copier types fixed in the wrapper type.
>
>
> If you have an indirect<Base> and you assign an indirect<Derived1> to
> it, and again assign
> an indirect<Derived2> to it, fixing the copier/deleter will stop the
> correct cloning and deletion of the target.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this topic, visit https://groups.google.com/a/
> isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAFk2RUZbR9yjJXYXDMx-
> HwRc8m282-xGk0Tn%2BwCmi3vBv0m_XA%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/CAHocnE_gYS37VLiV%3D%2BbAVCRWYGb-0-P1SoNPjoU9ygDuu6maBQ%40mail.gmail.com.
--001a1140b62449da720540621818
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">Sorry, I'm not sure what you mean. The deleter and copie=
r can still be copied and moved around with the managed object; it's ju=
st that all compatible indirect types must share the same types of deleter =
and copier.</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 3 Nov 2016 17:=
04, "Ville Voutilainen" <<a href=3D"mailto:ville.voutilainen@g=
mail.com">ville.voutilainen@gmail.com</a>> wrote:<br type=3D"attribution=
"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex">On 3 November 2016 at 10:54, Joseph Thomso=
n <<a href=3D"mailto:joseph.thomson@gmail.com">joseph.thomson@gmail.com<=
/a>> wrote:<br>
> However, one thing that hasn't sat right with me is the erasure of=
the types<br>
> of the deleter and copier. Of course, there may be an argument for the=
added<br>
> flexibility if the control block already exists, like in shared_ptr.<b=
r>
> However, now that we have a control block-less design, I think it make=
s<br>
> sense to have the deleter and copier types fixed in the wrapper type.<=
br>
<br>
<br>
If you have an indirect<Base> and you assign an indirect<Derived1&=
gt; to<br>
it, and again assign<br>
an indirect<Derived2> to it, fixing the copier/deleter will stop the<=
br>
correct cloning and deletion of the target.<br>
<br>
--<br>
You received this message because you are subscribed to a topic in the Goog=
le Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe" rel=3D"noreferr=
er" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/topic/s=
td-<wbr>proposals/EVA-oFQXpKo/<wbr>unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-proposals+unsubscrib=
e@<wbr>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/CAFk2RUZbR9yjJXYXDMx-HwRc8m282-xGk0Tn=
%2BwCmi3vBv0m_XA%40mail.gmail.com" rel=3D"noreferrer" target=3D"_blank">htt=
ps://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/<wbr>CA=
Fk2RUZbR9yjJXYXDMx-<wbr>HwRc8m282-xGk0Tn%2BwCmi3vBv0m_<wbr>XA%40mail.gmail.=
com</a>.<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/CAHocnE_gYS37VLiV%3D%2BbAVCRWYGb-0-P1=
SoNPjoU9ygDuu6maBQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE_gYS37=
VLiV%3D%2BbAVCRWYGb-0-P1SoNPjoU9ygDuu6maBQ%40mail.gmail.com</a>.<br />
--001a1140b62449da720540621818--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Nov 2016 11:25:46 +0200
Raw View
On 3 November 2016 at 11:22, Joseph Thomson <joseph.thomson@gmail.com> wrote:
> Sorry, I'm not sure what you mean. The deleter and copier can still be
> copied and moved around with the managed object; it's just that all
> compatible indirect types must share the same types of deleter and copier.
I don't know what "all compatible indirect types must share the same
types of deleter and copier"
is supposed to mean. I need to be able to assign an indirect<Derived1>
to an indirect<Base>,
and the copier and deleter for Base and Derived1 aren't compatible.
That assignment works
just fine if indirect type-erases the copier and the deleter.
--
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/CAFk2RUZ6h-Hd0TVVxEh1DAGsxey9hnfyn6WXvrN7%3D5-1eKgMmA%40mail.gmail.com.
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 17:54:20 +0800
Raw View
--001a1147ffc6b507da0540628a6e
Content-Type: text/plain; charset=UTF-8
Sorry. I was trying to be concise rather than technically correct.
When you have a unique_ptr<T, D> you can only assign it a unique_ptr<U, E>
if E is convertible to D. With indirect, the type erasure requires that the
deleter be passed to the type erased interface (whether that be a pointer
to a function taking void* or a virtual base class function). This means
that when you have an indirect<T, D, C> you can only assign it an
indirect<U, E, B> if D and E are the same type and C and B are the same
type, as their internal type erased interfaces must take the same types.
Of course you can also type erase the deleter and copier as the current
implementation does. It just comes at the cost of two std::any's and heap
allocation for larger deleter and copier objects.
On 3 Nov 2016 17:25, "Ville Voutilainen" <ville.voutilainen@gmail.com>
wrote:
> On 3 November 2016 at 11:22, Joseph Thomson <joseph.thomson@gmail.com>
> wrote:
> > Sorry, I'm not sure what you mean. The deleter and copier can still be
> > copied and moved around with the managed object; it's just that all
> > compatible indirect types must share the same types of deleter and
> copier.
>
> I don't know what "all compatible indirect types must share the same
> types of deleter and copier"
> is supposed to mean. I need to be able to assign an indirect<Derived1>
> to an indirect<Base>,
> and the copier and deleter for Base and Derived1 aren't compatible.
> That assignment works
> just fine if indirect type-erases the copier and the deleter.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this topic, visit https://groups.google.com/a/
> isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAFk2RUZ6h-Hd0TVVxEh1DAGsxey9hnfyn6WXvrN7
> %3D5-1eKgMmA%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/CAHocnE-R5PWMVtxTUXMVBxDZKPSK%2BdXuCH90GhHxKvKNmBQc%3Dw%40mail.gmail.com.
--001a1147ffc6b507da0540628a6e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">Sorry. I was trying to be concise rather than technically co=
rrect.</p>
<p dir=3D"ltr">When you have a unique_ptr<T, D> you can only assign i=
t a unique_ptr<U, E> if E is convertible to D. With indirect, the typ=
e erasure requires that the deleter be passed to the type erased interface =
(whether that be a pointer to a function taking void* or a virtual base cla=
ss function). This means that when you have an indirect<T, D, C> you =
can only assign it an indirect<U, E, B> if D and E are the same type =
and C and B are the same type, as their internal type erased interfaces mus=
t take the same types.</p>
<p dir=3D"ltr">Of course you can also type erase the deleter and copier as =
the current implementation does. It just comes at the cost of two std::any&=
#39;s and heap allocation for larger deleter and copier objects.</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 3 Nov 2016 17:=
25, "Ville Voutilainen" <<a href=3D"mailto:ville.voutilainen@g=
mail.com">ville.voutilainen@gmail.com</a>> wrote:<br type=3D"attribution=
"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex">On 3 November 2016 at 11:22, Joseph Thomso=
n <<a href=3D"mailto:joseph.thomson@gmail.com">joseph.thomson@gmail.com<=
/a>> wrote:<br>
> Sorry, I'm not sure what you mean. The deleter and copier can stil=
l be<br>
> copied and moved around with the managed object; it's just that al=
l<br>
> compatible indirect types must share the same types of deleter and cop=
ier.<br>
<br>
I don't know what "all compatible indirect types must share the sa=
me<br>
types of deleter and copier"<br>
is supposed to mean. I need to be able to assign an indirect<Derived1>=
;<br>
to an indirect<Base>,<br>
and the copier and deleter for Base and Derived1 aren't compatible.<br>
That assignment works<br>
just fine if indirect type-erases the copier and the deleter.<br>
<br>
--<br>
You received this message because you are subscribed to a topic in the Goog=
le Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe" rel=3D"noreferr=
er" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/topic/s=
td-<wbr>proposals/EVA-oFQXpKo/<wbr>unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-proposals+unsubscrib=
e@<wbr>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/CAFk2RUZ6h-Hd0TVVxEh1DAGsxey9hnfyn6WX=
vrN7%3D5-1eKgMmA%40mail.gmail.com" rel=3D"noreferrer" target=3D"_blank">htt=
ps://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/CAFk2RU=
Z6h-<wbr>Hd0TVVxEh1DAGsxey9hnfyn6WXvrN7<wbr>%3D5-1eKgMmA%40mail.gmail.com</=
a>.<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/CAHocnE-R5PWMVtxTUXMVBxDZKPSK%2BdXuCH=
90GhHxKvKNmBQc%3Dw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE-R5PWM=
VtxTUXMVBxDZKPSK%2BdXuCH90GhHxKvKNmBQc%3Dw%40mail.gmail.com</a>.<br />
--001a1147ffc6b507da0540628a6e--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Nov 2016 11:58:04 +0200
Raw View
On 3 November 2016 at 11:54, Joseph Thomson <joseph.thomson@gmail.com> wrote:
> Sorry. I was trying to be concise rather than technically correct.
>
> When you have a unique_ptr<T, D> you can only assign it a unique_ptr<U, E>
> if E is convertible to D. With indirect, the type erasure requires that the
> deleter be passed to the type erased interface (whether that be a pointer to
> a function taking void* or a virtual base class function). This means that
> when you have an indirect<T, D, C> you can only assign it an indirect<U, E,
> B> if D and E are the same type and C and B are the same type, as their
> internal type erased interfaces must take the same types.
>
> Of course you can also type erase the deleter and copier as the current
> implementation does. It just comes at the cost of two std::any's and heap
> allocation for larger deleter and copier objects.
It also comes with the benefit of actually being able to do
polymorphic copies, which is
what this type is all about.
--
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/CAFk2RUayHHJxmzVbGWKt4gA_CWfMi3S8UNGLSW%3DGs3JmRZQHcQ%40mail.gmail.com.
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 18:02:28 +0800
Raw View
--94eb2c089cecce5d15054062a743
Content-Type: text/plain; charset=UTF-8
T and U don't have to be the same type; T* and U* just have to be deletable
and copyable by the same type of deleter and copier (see my suggested
implementation for a polymorphic default deleter).
On 3 Nov 2016 17:58, "Ville Voutilainen" <ville.voutilainen@gmail.com>
wrote:
> On 3 November 2016 at 11:54, Joseph Thomson <joseph.thomson@gmail.com>
> wrote:
> > Sorry. I was trying to be concise rather than technically correct.
> >
> > When you have a unique_ptr<T, D> you can only assign it a unique_ptr<U,
> E>
> > if E is convertible to D. With indirect, the type erasure requires that
> the
> > deleter be passed to the type erased interface (whether that be a
> pointer to
> > a function taking void* or a virtual base class function). This means
> that
> > when you have an indirect<T, D, C> you can only assign it an indirect<U,
> E,
> > B> if D and E are the same type and C and B are the same type, as their
> > internal type erased interfaces must take the same types.
> >
> > Of course you can also type erase the deleter and copier as the current
> > implementation does. It just comes at the cost of two std::any's and heap
> > allocation for larger deleter and copier objects.
>
> It also comes with the benefit of actually being able to do
> polymorphic copies, which is
> what this type is all about.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this topic, visit https://groups.google.com/a/
> isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAFk2RUayHHJxmzVbGWKt4gA_
> CWfMi3S8UNGLSW%3DGs3JmRZQHcQ%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/CAHocnE8z%3DR-%3DCnXx2%2BqudrXW__eXYu66YPZqpePwCd7oDgRLeQ%40mail.gmail.com.
--94eb2c089cecce5d15054062a743
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">T and U don't have to be the same type; T* and U* just h=
ave to be deletable and copyable by the same type of deleter and copier (se=
e my suggested implementation for a polymorphic default deleter).</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 3 Nov 2016 17:=
58, "Ville Voutilainen" <<a href=3D"mailto:ville.voutilainen@g=
mail.com">ville.voutilainen@gmail.com</a>> wrote:<br type=3D"attribution=
"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex">On 3 November 2016 at 11:54, Joseph Thomso=
n <<a href=3D"mailto:joseph.thomson@gmail.com">joseph.thomson@gmail.com<=
/a>> wrote:<br>
> Sorry. I was trying to be concise rather than technically correct.<br>
><br>
> When you have a unique_ptr<T, D> you can only assign it a unique=
_ptr<U, E><br>
> if E is convertible to D. With indirect, the type erasure requires tha=
t the<br>
> deleter be passed to the type erased interface (whether that be a poin=
ter to<br>
> a function taking void* or a virtual base class function). This means =
that<br>
> when you have an indirect<T, D, C> you can only assign it an ind=
irect<U, E,<br>
> B> if D and E are the same type and C and B are the same type, as t=
heir<br>
> internal type erased interfaces must take the same types.<br>
><br>
> Of course you can also type erase the deleter and copier as the curren=
t<br>
> implementation does. It just comes at the cost of two std::any's a=
nd heap<br>
> allocation for larger deleter and copier objects.<br>
<br>
It also comes with the benefit of actually being able to do<br>
polymorphic copies, which is<br>
what this type is all about.<br>
<br>
--<br>
You received this message because you are subscribed to a topic in the Goog=
le Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe" rel=3D"noreferr=
er" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/topic/s=
td-<wbr>proposals/EVA-oFQXpKo/<wbr>unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-proposals+unsubscrib=
e@<wbr>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/CAFk2RUayHHJxmzVbGWKt4gA_CWfMi3S8UNGL=
SW%3DGs3JmRZQHcQ%40mail.gmail.com" rel=3D"noreferrer" target=3D"_blank">htt=
ps://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/<wbr>CA=
Fk2RUayHHJxmzVbGWKt4gA_<wbr>CWfMi3S8UNGLSW%3DGs3JmRZQHcQ%<wbr>40mail.gmail.=
com</a>.<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/CAHocnE8z%3DR-%3DCnXx2%2BqudrXW__eXYu=
66YPZqpePwCd7oDgRLeQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE8z%3=
DR-%3DCnXx2%2BqudrXW__eXYu66YPZqpePwCd7oDgRLeQ%40mail.gmail.com</a>.<br />
--94eb2c089cecce5d15054062a743--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Nov 2016 12:27:40 +0200
Raw View
On 3 November 2016 at 12:02, Joseph Thomson <joseph.thomson@gmail.com> wrote:
> T and U don't have to be the same type; T* and U* just have to be deletable
> and copyable by the same type of deleter and copier (see my suggested
> implementation for a polymorphic default deleter).
I don't see how a copier for "T*" (which should really be a copier for
T, not T*) can possibly
copy a U when U is a type derived from T.
--
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/CAFk2RUYMFLkEGdKnris7qwtsnN2EkYdCRVvnCbjXMWkkSJDm-w%40mail.gmail.com.
.
Author: mihailnajdenov@gmail.com
Date: Thu, 3 Nov 2016 03:38:15 -0700 (PDT)
Raw View
------=_Part_116_470918934.1478169495987
Content-Type: multipart/alternative;
boundary="----=_Part_117_1626692255.1478169495987"
------=_Part_117_1626692255.1478169495987
Content-Type: text/plain; charset=UTF-8
On Thursday, November 3, 2016 at 12:02:31 PM UTC+2, Joseph Thomson wrote:
>
> T and U don't have to be the same type; T* and U* just have to be
> deletable and copyable by the same type of deleter and copier (see my
> suggested implementation for a polymorphic default deleter).
>
>> ...
>>
>
This can be made to work, for the delete easily, because of virtual dtors.
For copier I don't see how we can just "convert" one into another. Given
your templated polymorphic delete it is fine, but the same class used for
copy will not work because we need a type, different then the current one
to call it.
It makes sense that the same deleter and copier would be used for an
> inheritance hierarchy of types.
I can't see this to be true for a copier.
But above all, I don't see the benefit. If it is the size is the problem -
a smart impl. will not use std::any
It will use a buffer, shared b/w copier, deleter and the ugly cast chain -
a trivial deleter makes rooms for bigger copier, a trivial copier makes
room for N conversions without allocations.
And lets not forget about functors - we probably want to preserve the
copier and delete as-is on assignment instead of "converting" it.
--
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/3c9280cd-c507-431c-8571-6ebd50968b76%40isocpp.org.
------=_Part_117_1626692255.1478169495987
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, November 3, 2016 at 12:02:31 PM UTC+2=
, Joseph Thomson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><p dir=
=3D"ltr">T and U don't have to be the same type; T* and U* just have to=
be deletable and copyable by the same type of deleter and copier (see my s=
uggested implementation for a polymorphic default deleter).</p><div><div cl=
ass=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
.8ex;border-left:1px #ccc solid;padding-left:1ex">...<br></blockquote></di=
v></div></blockquote><div><br></div><div>This can be made to work, for the =
delete easily, because of virtual dtors. </div><div>For copier I don't =
see how we can just "convert" one into another. Given your templa=
ted polymorphic delete it is fine, but the same class used for copy will no=
t work because we need a type, different then the current one to call it. <=
/div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0px =
0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bo=
rder-left-width: 1px; border-left-style: solid;">It makes sense that the sa=
me deleter and copier would be used for an inheritance hierarchy of types.<=
/blockquote><div><br></div><div>I can't see this to be true for a copie=
r.=C2=A0</div><div><br></div><div>But above all, I don't see the benefi=
t. If it is the size is the problem - a smart impl. will not use std::any <=
/div><div>It will use a buffer, shared b/w copier, deleter and the ugly cas=
t chain - a trivial deleter makes rooms for bigger copier, a trivial copier=
makes room for N conversions without allocations.</div><div><br></div><div=
>And lets not forget about functors - we probably want to preserve the copi=
er and delete as-is on assignment instead of "converting" it.=C2=
=A0</div><div><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/3c9280cd-c507-431c-8571-6ebd50968b76%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3c9280cd-c507-431c-8571-6ebd50968b76=
%40isocpp.org</a>.<br />
------=_Part_117_1626692255.1478169495987--
------=_Part_116_470918934.1478169495987--
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 18:42:54 +0800
Raw View
--94eb2c094a2c62d37f0540633871
Content-Type: text/plain; charset=UTF-8
struct default_polymorphic_copier
{
template <typename T>
T* operator()(T const& t) const
{
return new T(t);
}
};
You can provide separate implementations for different types if need be.
On 3 Nov 2016 18:27, "Ville Voutilainen" <ville.voutilainen@gmail.com>
wrote:
> On 3 November 2016 at 12:02, Joseph Thomson <joseph.thomson@gmail.com>
> wrote:
> > T and U don't have to be the same type; T* and U* just have to be
> deletable
> > and copyable by the same type of deleter and copier (see my suggested
> > implementation for a polymorphic default deleter).
>
>
> I don't see how a copier for "T*" (which should really be a copier for
> T, not T*) can possibly
> copy a U when U is a type derived from T.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this topic, visit https://groups.google.com/a/
> isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAFk2RUYMFLkEGdKnris7qwtsnN2Ek
> YdCRVvnCbjXMWkkSJDm-w%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/CAHocnE-1V6e-CDqNq-7gMAm%2B6JYSg4DB%2B_AebOLJSDQ%2B8vj5YA%40mail.gmail.com.
--94eb2c094a2c62d37f0540633871
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">struct default_polymorphic_copier<br>
{<br>
=C2=A0=C2=A0=C2=A0 template <typename T><br>
=C2=A0=C2=A0=C2=A0 T* operator()(T const& t) const<br>
=C2=A0=C2=A0=C2=A0 {<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return new T(t);<br>
=C2=A0=C2=A0=C2=A0 }<br>
};</p>
<p dir=3D"ltr">You can provide separate implementations for different types=
if need be.<br>
</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 3 Nov 2016 18:=
27, "Ville Voutilainen" <<a href=3D"mailto:ville.voutilainen@g=
mail.com">ville.voutilainen@gmail.com</a>> wrote:<br type=3D"attribution=
"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex">On 3 November 2016 at 12:02, Joseph Thomso=
n <<a href=3D"mailto:joseph.thomson@gmail.com">joseph.thomson@gmail.com<=
/a>> wrote:<br>
> T and U don't have to be the same type; T* and U* just have to be =
deletable<br>
> and copyable by the same type of deleter and copier (see my suggested<=
br>
> implementation for a polymorphic default deleter).<br>
<br>
<br>
I don't see how a copier for "T*" (which should really be a c=
opier for<br>
T, not T*) can possibly<br>
copy a U when U is a type derived from T.<br>
<br>
--<br>
You received this message because you are subscribed to a topic in the Goog=
le Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/EVA-oFQXpKo/unsubscribe" rel=3D"noreferr=
er" target=3D"_blank">https://groups.google.com/a/<wbr>isocpp.org/d/topic/s=
td-<wbr>proposals/EVA-oFQXpKo/<wbr>unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-proposals+unsubscrib=
e@<wbr>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/CAFk2RUYMFLkEGdKnris7qwtsnN2EkYdCRVvn=
CbjXMWkkSJDm-w%40mail.gmail.com" rel=3D"noreferrer" target=3D"_blank">https=
://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/<wbr>CAFk=
2RUYMFLkEGdKnris7qwtsnN2Ek<wbr>YdCRVvnCbjXMWkkSJDm-w%40mail.<wbr>gmail.com<=
/a>.<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/CAHocnE-1V6e-CDqNq-7gMAm%2B6JYSg4DB%2=
B_AebOLJSDQ%2B8vj5YA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE-1V6=
e-CDqNq-7gMAm%2B6JYSg4DB%2B_AebOLJSDQ%2B8vj5YA%40mail.gmail.com</a>.<br />
--94eb2c094a2c62d37f0540633871--
.
Author: mihailnajdenov@gmail.com
Date: Thu, 3 Nov 2016 03:47:52 -0700 (PDT)
Raw View
------=_Part_69_1210923872.1478170073052
Content-Type: multipart/alternative;
boundary="----=_Part_70_1678032063.1478170073052"
------=_Part_70_1678032063.1478170073052
Content-Type: text/plain; charset=UTF-8
On Thursday, November 3, 2016 at 12:42:56 PM UTC+2, Joseph Thomson wrote:
>
> struct default_polymorphic_copier
> {
> template <typename T>
> T* operator()(T const& t) const
> {
> return new T(t);
> }
> };
>
> You can provide separate implementations for different types if need be.
>
>> ...
>>
>
But how can you call this from a T if it meant to copy a U?
--
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/e830c6b3-420e-4b90-9700-be1bb5716a66%40isocpp.org.
------=_Part_70_1678032063.1478170073052
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, November 3, 2016 at 12:42:56 PM UTC+2=
, Joseph Thomson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><p dir=
=3D"ltr">struct default_polymorphic_copier<br>
{<br>
=C2=A0=C2=A0=C2=A0 template <typename T><br>
=C2=A0=C2=A0=C2=A0 T* operator()(T const& t) const<br>
=C2=A0=C2=A0=C2=A0 {<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return new T(t);<br>
=C2=A0=C2=A0=C2=A0 }<br>
};</p>
<p dir=3D"ltr">You can provide separate implementations for different types=
if need be.<br>
</p>
<div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">...<br></blo=
ckquote></div></div></blockquote><div><br></div><div>But=C2=A0how can you c=
all this from a T if it meant to copy a U? </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/e830c6b3-420e-4b90-9700-be1bb5716a66%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e830c6b3-420e-4b90-9700-be1bb5716a66=
%40isocpp.org</a>.<br />
------=_Part_70_1678032063.1478170073052--
------=_Part_69_1210923872.1478170073052--
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 19:20:29 +0800
Raw View
--94eb2c0775b8cda59e054063beb1
Content-Type: text/plain; charset=UTF-8
The polymorphic deleter will work even for types without virtual
destructors. Parameterizing the member function is functionally the same as
parameterizing the class; it's just a necessity to define a deleter that
operates on all types. Perhaps my use of "polymorphic" is confusing. I mean
compile time rather than run time polymorphism.
As for the same copier, I mean the logic that copies objects in an
inheritance hierarchy is likely to use the same logic, and so could be
conveniently encapsulated in the same type. Of course, some actual use
cases would be handy here.
As for the pros and cons, it may well not be worth it. However, I think
type erasing the copier and deleter will always take more space. If space
or heap allocations with bigger copier and deleter types is a concern, this
is a potential modification.
--
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/CAHocnE_1piqRTGtU_MxuOfTU8Fv7V0%2BdupLkvE%2BMxMKxmOxVJA%40mail.gmail.com.
--94eb2c0775b8cda59e054063beb1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">The polymorphic deleter will work even for types without vir=
tual destructors. Parameterizing the member function is functionally the sa=
me as parameterizing the class; it's just a necessity to define a delet=
er that operates on all types. Perhaps my use of "polymorphic" is=
confusing. I mean compile time rather than run time polymorphism.</p>
<p dir=3D"ltr">As for the same copier, I mean the logic that copies objects=
in an inheritance hierarchy is likely to use the same logic, and so could =
be conveniently encapsulated in the same type. Of course, some actual use c=
ases would be handy here.</p>
<p dir=3D"ltr">As for the pros and cons, it may well not be worth it. Howev=
er, I think type erasing the copier and deleter will always take more space=
.. If space or heap allocations with bigger copier and deleter types is a co=
ncern, this is a potential modification.</p>
<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/CAHocnE_1piqRTGtU_MxuOfTU8Fv7V0%2Bdup=
LkvE%2BMxMKxmOxVJA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE_1piqR=
TGtU_MxuOfTU8Fv7V0%2BdupLkvE%2BMxMKxmOxVJA%40mail.gmail.com</a>.<br />
--94eb2c0775b8cda59e054063beb1--
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 19:44:23 +0800
Raw View
--94eb2c1928b448c1e8054064143b
Content-Type: text/plain; charset=UTF-8
The implementation looks something like this:
template <typename U>
void* type_erased_copy(copier_type const& c, void* p)
{
return reinterpret_cast<void*>(c(reinterpret_cast<U*>(p)));
}
I will try to upload a working implementation soon (can also provide a
version with type erased deleter and copier for Github).
On 3 Nov 2016 18:47, <mihailnajdenov@gmail.com> wrote:
On Thursday, November 3, 2016 at 12:42:56 PM UTC+2, Joseph Thomson wrote:
> struct default_polymorphic_copier
> {
> template <typename T>
> T* operator()(T const& t) const
> {
> return new T(t);
> }
> };
>
> You can provide separate implementations for different types if need be.
>
>> ...
>>
>
But how can you call this from a T if it meant to copy a U?
--
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/CAHocnE9mG19qVL6V_66zo2_4xtbMB_CWBoru0WmgAJrveMi-2Q%40mail.gmail.com.
--94eb2c1928b448c1e8054064143b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">The implementation looks something like this:</p>
<p dir=3D"ltr">template <typename U><br>
void* type_erased_copy(copier_type const& c, void* p)<br>
{<br>
=C2=A0=C2=A0=C2=A0 return reinterpret_cast<void*>(c(reinterpret_cast&=
lt;U*>(p)));<br>
}</p>
<p dir=3D"ltr">I will try to upload a working implementation soon (can also=
provide a version with type erased deleter and copier for Github).</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 3 Nov 2016 18:=
47, <<a href=3D"mailto:mihailnajdenov@gmail.com">mihailnajdenov@gmail.c=
om</a>> wrote:<br type=3D"attribution"><blockquote class=3D"quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr"><div class=3D"quoted-text"><br><br>On Thursday, November 3, 2016 a=
t 12:42:56 PM UTC+2, Joseph Thomson wrote:</div><blockquote class=3D"gmail_=
quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;paddi=
ng-left:1ex"><div class=3D"quoted-text"><p dir=3D"ltr">struct default_polym=
orphic_copier<br>
{<br>
=C2=A0=C2=A0=C2=A0 template <typename T><br>
=C2=A0=C2=A0=C2=A0 T* operator()(T const& t) const<br>
=C2=A0=C2=A0=C2=A0 {<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return new T(t);<br>
=C2=A0=C2=A0=C2=A0 }<br>
};</p>
<p dir=3D"ltr">You can provide separate implementations for different types=
if need be.<br>
</p>
</div><div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">...<br=
></blockquote></div></div></blockquote><div><br></div><div>But=C2=A0how can=
you call this from a T if it meant to copy a U? </div></div></blockquote><=
/div><br></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/CAHocnE9mG19qVL6V_66zo2_4xtbMB_CWBoru=
0WmgAJrveMi-2Q%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE9mG19qVL6V=
_66zo2_4xtbMB_CWBoru0WmgAJrveMi-2Q%40mail.gmail.com</a>.<br />
--94eb2c1928b448c1e8054064143b--
.
Author: mihailnajdenov@gmail.com
Date: Thu, 3 Nov 2016 05:36:23 -0700 (PDT)
Raw View
------=_Part_214_1960842435.1478176583572
Content-Type: multipart/alternative;
boundary="----=_Part_215_454407315.1478176583572"
------=_Part_215_454407315.1478176583572
Content-Type: text/plain; charset=UTF-8
On Thursday, November 3, 2016 at 1:44:25 PM UTC+2, Joseph Thomson wrote:
>
> The implementation looks something like this:
>
> template <typename U>
> void* type_erased_copy(copier_type const& c, void* p)
> {
> return reinterpret_cast<void*>(c(reinterpret_cast<U*>(p)));
> }
>
> I will try to upload a working implementation soon (can also provide a
> version with type erased deleter and copier for Github).
>
>
You still need copier_type to be accepting a U, but stored it in a
indirect<T>.
I don't see how copier_type can be such to work with all types.
--
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/433dd6d7-eab0-4c2f-93b1-afed7845f0fc%40isocpp.org.
------=_Part_215_454407315.1478176583572
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, November 3, 2016 at 1:44:25 PM UTC+2,=
Joseph Thomson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><p dir=
=3D"ltr">The implementation looks something like this:</p>
<p dir=3D"ltr">template <typename U><br>
void* type_erased_copy(copier_type const& c, void* p)<br>
{<br>
=C2=A0=C2=A0=C2=A0 return reinterpret_cast<void*>(c(<wbr>reinterpret_=
cast<U*>(p)));<br>
}</p>
<p dir=3D"ltr">I will try to upload a working implementation soon (can also=
provide a version with type erased deleter and copier for Github).</p>
<div><br></div></blockquote><div><br></div><div>You still need copier_type =
to be=C2=A0accepting a=C2=A0U, but stored it in a indirect<T>. =C2=A0=
</div><div><br></div><div>I don't see how copier_type can be such to wo=
rk with all types. </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/433dd6d7-eab0-4c2f-93b1-afed7845f0fc%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/433dd6d7-eab0-4c2f-93b1-afed7845f0fc=
%40isocpp.org</a>.<br />
------=_Part_215_454407315.1478176583572--
------=_Part_214_1960842435.1478176583572--
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 21:05:59 +0800
Raw View
--001a114d74a81970500540653819
Content-Type: text/plain; charset=UTF-8
That's why indirect<T, ...> and indirect<U, ...> must have the same deleter
and copier types. Ones that overload operator() for both T and U. It's a
requirement of this design. If they don't share a deleter type or a copier
type, you cannot convert one to the other.
On 3 Nov 2016 20:36, <mihailnajdenov@gmail.com> wrote:
>
>
> On Thursday, November 3, 2016 at 1:44:25 PM UTC+2, Joseph Thomson wrote:
>>
>> The implementation looks something like this:
>>
>> template <typename U>
>> void* type_erased_copy(copier_type const& c, void* p)
>> {
>> return reinterpret_cast<void*>(c(reinterpret_cast<U*>(p)));
>> }
>>
>> I will try to upload a working implementation soon (can also provide a
>> version with type erased deleter and copier for Github).
>>
>>
> You still need copier_type to be accepting a U, but stored it in a
> indirect<T>.
>
> I don't see how copier_type can be such to work with all types.
>
--
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/CAHocnE_1y8qsC1n9QmuySwJ533LX95W%3D4Sc4HKaZ%2B1k77KKOpQ%40mail.gmail.com.
--001a114d74a81970500540653819
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">That's why indirect<T, ...> and indirect<U, ...=
> must have the same deleter and copier types. Ones that overload operat=
or() for both T and U. It's a requirement of this design. If they don&#=
39;t share a deleter type or a copier type, you cannot convert one to the o=
ther.</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 3 Nov 2016 20:=
36, <<a href=3D"mailto:mihailnajdenov@gmail.com">mihailnajdenov@gmail.c=
om</a>> wrote:<br type=3D"attribution"><blockquote class=3D"gmail_quote"=
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr"><br><br>On Thursday, November 3, 2016 at 1:44:25 PM UTC+2, J=
oseph Thomson wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;mar=
gin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir=3D"ltr">=
The implementation looks something like this:</p>
<p dir=3D"ltr">template <typename U><br>
void* type_erased_copy(copier_type const& c, void* p)<br>
{<br>
=C2=A0=C2=A0=C2=A0 return reinterpret_cast<void*>(c(rein<wbr>terpret_=
cast<U*>(p)));<br>
}</p>
<p dir=3D"ltr">I will try to upload a working implementation soon (can also=
provide a version with type erased deleter and copier for Github).</p>
<div><br></div></blockquote><div><br></div><div>You still need copier_type =
to be=C2=A0accepting a=C2=A0U, but stored it in a indirect<T>. =C2=A0=
</div><div><br></div><div>I don't see how copier_type can be such to wo=
rk with all types. </div></div></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/CAHocnE_1y8qsC1n9QmuySwJ533LX95W%3D4S=
c4HKaZ%2B1k77KKOpQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE_1y8qs=
C1n9QmuySwJ533LX95W%3D4Sc4HKaZ%2B1k77KKOpQ%40mail.gmail.com</a>.<br />
--001a114d74a81970500540653819--
.
Author: mihailnajdenov@gmail.com
Date: Thu, 3 Nov 2016 06:28:27 -0700 (PDT)
Raw View
------=_Part_238_594703244.1478179707344
Content-Type: multipart/alternative;
boundary="----=_Part_239_207881160.1478179707345"
------=_Part_239_207881160.1478179707345
Content-Type: text/plain; charset=UTF-8
On Thursday, November 3, 2016 at 3:06:02 PM UTC+2, Joseph Thomson wrote:
>
> That's why indirect<T, ...> and indirect<U, ...> must have the same
> deleter and copier types. Ones that overload operator() for both T and U.
> It's a requirement of this design. If they don't share a deleter type or a
> copier type, you cannot convert one to the other.
>
>> ...
>>
>
Even if overloaded, the copier must be called with the correct type at the
call site, so the correct overload can be picked.
This is hard in this case because you don't know the correct type from
an instance of another type - a T calling the copier in such a way, U is
copied without T knowing anything about U.
The stub works, though it is very limited, but still enough so the original
deleter/copier is always called, from every instance - this is what the
current impl. does.
--
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/6807feef-5b89-4343-b216-ea6f41014c0c%40isocpp.org.
------=_Part_239_207881160.1478179707345
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, November 3, 2016 at 3:06:02 PM UTC+2,=
Joseph Thomson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><p dir=
=3D"ltr">That's why indirect<T, ...> and indirect<U, ...> m=
ust have the same deleter and copier types. Ones that overload operator() f=
or both T and U. It's a requirement of this design. If they don't s=
hare a deleter type or a copier type, you cannot convert one to the other.<=
/p>
<div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"=
ltr"><div>...</div></div></blockquote></div></div></blockquote><div><br></d=
iv><div>Even if overloaded, the copier must be called with the correct type=
at the call site, so the correct overload can be picked.</div><div>This is=
hard in this case because you don't know the correct type from an=C2=
=A0instance of another type - a T calling the copier in such a way, U is co=
pied without T knowing anything=C2=A0about=C2=A0U.</div><div>The stub works=
, though it=C2=A0is very limited, but still enough so the original deleter/=
copier is always called, from every instance -=C2=A0this is what the curren=
t impl. does.=C2=A0</div><div><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/6807feef-5b89-4343-b216-ea6f41014c0c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6807feef-5b89-4343-b216-ea6f41014c0c=
%40isocpp.org</a>.<br />
------=_Part_239_207881160.1478179707345--
------=_Part_238_594703244.1478179707344--
.
Author: Joseph Thomson <joseph.thomson@gmail.com>
Date: Thu, 3 Nov 2016 21:48:25 +0800
Raw View
--001a114d74a8dde39d054065cfed
Content-Type: text/plain; charset=UTF-8
The type of the managed object is captured by the type erased copier on
construction just like in your design. Just replace the std::any with
copier_type and call the overloaded operator() instead of doing an
any_cast, and you've got my modified design.
On 3 Nov 2016 21:28, <mihailnajdenov@gmail.com> wrote:
>
>
> On Thursday, November 3, 2016 at 3:06:02 PM UTC+2, Joseph Thomson wrote:
>>
>> That's why indirect<T, ...> and indirect<U, ...> must have the same
>> deleter and copier types. Ones that overload operator() for both T and U.
>> It's a requirement of this design. If they don't share a deleter type or a
>> copier type, you cannot convert one to the other.
>>
>>> ...
>>>
>>
> Even if overloaded, the copier must be called with the correct type at the
> call site, so the correct overload can be picked.
> This is hard in this case because you don't know the correct type from
> an instance of another type - a T calling the copier in such a way, U is
> copied without T knowing anything about U.
> The stub works, though it is very limited, but still enough so the
> original deleter/copier is always called, from every instance - this is
> what the current impl. does.
>
>
--
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/CAHocnE89PmRp1cXJ0XDSnz_Cx%2ByMkqzFOBOonh9s%2BP_koQ4Uzw%40mail.gmail.com.
--001a114d74a8dde39d054065cfed
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">The type of the managed object is captured by the type erase=
d copier on construction just like in your design. Just replace the std::an=
y with copier_type and call the overloaded operator() instead of doing an a=
ny_cast, and you've got my modified design.</p>
<div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On 3 Nov 2016 21:=
28, <<a href=3D"mailto:mihailnajdenov@gmail.com">mihailnajdenov@gmail.c=
om</a>> wrote:<br type=3D"attribution"><blockquote class=3D"gmail_quote"=
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr"><br><br>On Thursday, November 3, 2016 at 3:06:02 PM UTC+2, J=
oseph Thomson wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;mar=
gin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir=3D"ltr">=
That's why indirect<T, ...> and indirect<U, ...> must have =
the same deleter and copier types. Ones that overload operator() for both T=
and U. It's a requirement of this design. If they don't share a de=
leter type or a copier type, you cannot convert one to the other.</p>
<div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"=
ltr"><div>...</div></div></blockquote></div></div></blockquote><div><br></d=
iv><div>Even if overloaded, the copier must be called with the correct type=
at the call site, so the correct overload can be picked.</div><div>This is=
hard in this case because you don't know the correct type from an=C2=
=A0instance of another type - a T calling the copier in such a way, U is co=
pied without T knowing anything=C2=A0about=C2=A0U.</div><div>The stub works=
, though it=C2=A0is very limited, but still enough so the original deleter/=
copier is always called, from every instance -=C2=A0this is what the curren=
t impl. does.=C2=A0</div><div><br></div></div></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/CAHocnE89PmRp1cXJ0XDSnz_Cx%2ByMkqzFOB=
Oonh9s%2BP_koQ4Uzw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHocnE89PmRp=
1cXJ0XDSnz_Cx%2ByMkqzFOBOonh9s%2BP_koQ4Uzw%40mail.gmail.com</a>.<br />
--001a114d74a8dde39d054065cfed--
.
Author: mihailnajdenov@gmail.com
Date: Thu, 3 Nov 2016 07:56:30 -0700 (PDT)
Raw View
------=_Part_324_1668353629.1478184990248
Content-Type: multipart/alternative;
boundary="----=_Part_325_1029724533.1478184990248"
------=_Part_325_1029724533.1478184990248
Content-Type: text/plain; charset=UTF-8
On Thursday, November 3, 2016 at 3:48:28 PM UTC+2, Joseph Thomson wrote:
>
> The type of the managed object is captured by the type erased copier on
> construction just like in your design. Just replace the std::any with
> copier_type and call the overloaded operator() instead of doing an
> any_cast, and you've got my modified design.
>
>> ...
>>
>
Ok, I get it now, I was under the impression, you are removing the
limitation that copy must be called on the initial object type and that
type only. There was quite ambiguity what is "the same copier" and "works
for all types".
I get it now - the versions are behind a type as members, instead behind
an std::any,
but there is always one and only one active version in flight, for a given
instance, and it is always for the initial type only.
--
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/1854d7a4-f520-45bc-8f58-1544b85c1d41%40isocpp.org.
------=_Part_325_1029724533.1478184990248
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, November 3, 2016 at 3:48:28 PM UTC+2,=
Joseph Thomson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><p dir=
=3D"ltr">The type of the managed object is captured by the type erased copi=
er on construction just like in your design. Just replace the std::any with=
copier_type and call the overloaded operator() instead of doing an any_cas=
t, and you've got my modified design.</p>
<div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"=
ltr"><div>...</div></div></blockquote></div></div></blockquote><div><br></d=
iv><div><div>Ok, I get it now, I was under the impression, you are removing=
the limitation that=C2=A0copy=C2=A0must be=C2=A0called on the initial obje=
ct type=C2=A0and that type only.=C2=A0There was quite ambiguity what is &qu=
ot;the same copier" and "works for all types". </div><div>I =
get it=C2=A0now - the versions are behind a type as members,=C2=A0instead b=
ehind an=C2=A0std::any,</div><div>but there is always one and only one acti=
ve=C2=A0version in flight, for a given instance, and it=C2=A0is always for =
the initial type only. </div></div><div>=C2=A0</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/1854d7a4-f520-45bc-8f58-1544b85c1d41%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1854d7a4-f520-45bc-8f58-1544b85c1d41=
%40isocpp.org</a>.<br />
------=_Part_325_1029724533.1478184990248--
------=_Part_324_1668353629.1478184990248--
.