Topic: Complexities caused by using unique_ptr and
Author: Sean Middleditch <sean@middleditch.us>
Date: Sun, 26 Mar 2017 15:11:06 -0700
Raw View
--001a113567bed6a331054ba980bf
Content-Type: text/plain; charset=UTF-8
On Fri, Mar 24, 2017 at 3:25 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
>
>> Basically, you want to write something like:
>>
>> iterable<T&> foo::get_things() { return make_iterable(_things, [](auto&
>> p){ return *p; }); }
>>
>>
> That's a really bad tradeoff: type-erasing performance plus the cost of
> filtering, all just to gain some increased genericity.
>
Not at all, because that'd be a template that gets fully inlined and result
in identical machine code (assuming a suitably capable optimizer). Again,
that's all writeable _today_ if you put in the leg work (we have in our
libraries), it's just not a standard pattern in the C++ libraries, and you
don't get the niceties that concepts provides wrt errors and composition.
Generators and mapped iterables aren't new here, just like C++ lambdas
weren't new - they're just syntactic sugar for a well-established pattern.
>
> But Boost.Range already has something like this: `any_range
> <http://www.boost.org/doc/libs/1_63_0/libs/range/doc/html/range/reference/ranges/any_range.html>`,
> coupled with transforming the input range by a function
> <http://www.boost.org/doc/libs/1_63_0/libs/range/doc/html/range/reference/adaptors/reference/transformed.html>
> .
>
> --
> 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/nc5Sj-LtKbA/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/136fc743-bc63-48c8-
> b1d5-dc4084dd13cf%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/136fc743-bc63-48c8-b1d5-dc4084dd13cf%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
Sean Middleditch
http://seanmiddleditch.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/CALQmNFgAe4B2tiqjA7Mq1TWXWdt-OMAUD41AKzuxh_6_X%3DuRcQ%40mail.gmail.com.
--001a113567bed6a331054ba980bf
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On F=
ri, Mar 24, 2017 at 3:25 PM, Nicol Bolas <span dir=3D"ltr"><<a href=3D"m=
ailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>></s=
pan> 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"><span class=
=3D""><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><br></d=
iv><div>Basically, you want to write something like:</div><div><br></div><d=
iv>=C2=A0 iterable<T&> foo::get_things() { return make_iterable(_=
things, [](auto& p){ return *p; }); }<br></div><div><br></div><div></di=
v></div></blockquote></span><div><br>That's a really bad tradeoff: type=
-erasing performance plus the cost of filtering, all just to gain some incr=
eased genericity. <br></div></div></blockquote><div><br></div><div>Not at a=
ll, because that'd be a template that gets fully inlined and result in =
identical machine code (assuming a suitably capable optimizer). Again, that=
's all writeable _today_ if you put in the leg work (we have in our lib=
raries), it's just not a standard pattern in the C++ libraries, and you=
don't get the niceties that concepts provides wrt errors and compositi=
on.</div><div><br></div><div>Generators and mapped iterables aren't new=
here, just like C++ lambdas weren't new - they're just syntactic s=
ugar for a well-established pattern.</div><div>=C2=A0</div><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad=
ding-left:1ex"><div dir=3D"ltr"><div><br>But Boost.Range already has someth=
ing like this: `<a href=3D"http://www.boost.org/doc/libs/1_63_0/libs/range/=
doc/html/range/reference/ranges/any_range.html" target=3D"_blank">any_range=
</a>`, coupled with <a href=3D"http://www.boost.org/doc/libs/1_63_0/libs/ra=
nge/doc/html/range/reference/adaptors/reference/transformed.html" target=3D=
"_blank">transforming the input range by a function</a>.<br></div></div><sp=
an class=3D"">
<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/nc5Sj-LtKbA/unsubscribe" target=3D"_blan=
k">https://groups.google.com/a/<wbr>isocpp.org/d/topic/std-<wbr>proposals/n=
c5Sj-LtKbA/<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></span>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/136fc743-bc63-48c8-b1d5-dc4084dd13cf%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/136f=
c743-bc63-48c8-<wbr>b1d5-dc4084dd13cf%40isocpp.org</a><wbr>.<br>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div class=
=3D"gmail_signature" data-smartmail=3D"gmail_signature">Sean Middleditch<br=
><a href=3D"http://seanmiddleditch.com" target=3D"_blank">http://seanmiddle=
ditch.com</a></div>
</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/CALQmNFgAe4B2tiqjA7Mq1TWXWdt-OMAUD41A=
Kzuxh_6_X%3DuRcQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALQmNFgAe4B2ti=
qjA7Mq1TWXWdt-OMAUD41AKzuxh_6_X%3DuRcQ%40mail.gmail.com</a>.<br />
--001a113567bed6a331054ba980bf--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 26 Mar 2017 18:12:05 -0700 (PDT)
Raw View
------=_Part_2792_1819910155.1490577125313
Content-Type: multipart/alternative;
boundary="----=_Part_2793_825116473.1490577125313"
------=_Part_2793_825116473.1490577125313
Content-Type: text/plain; charset=UTF-8
On Sunday, March 26, 2017 at 6:11:08 PM UTC-4, Sean Middleditch wrote:
>
> On Fri, Mar 24, 2017 at 3:25 PM, Nicol Bolas <jmck...@gmail.com
> <javascript:>> wrote:
>
>>
>>> Basically, you want to write something like:
>>>
>>> iterable<T&> foo::get_things() { return make_iterable(_things,
>>> [](auto& p){ return *p; }); }
>>>
>>>
>> That's a really bad tradeoff: type-erasing performance plus the cost of
>> filtering, all just to gain some increased genericity.
>>
>
> Not at all, because that'd be a template that gets fully inlined and
> result in identical machine code (assuming a suitably capable optimizer).
>
How? `iterable` doesn't specify the type of iterator used to iterate over
`_things`, nor does it specify the type of range that `_things` is. But it
still has to store either the range or an iterator pair over that range.
Therefore, the storage for those things must be type-erased in some
fashion. And that requires some form of indirect call to move to the next
item in the iterator, as well as to call the functor. Not to mention having
to type-erase the functor itself.
And type-erasure is the enemy of inlining.
If that were an `iterable<span<T>, function_type>`, then I could buy the
inlining. But not so long as type erasure has to be used.
--
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/0d3f5162-b2f9-4389-a0ec-4e3928492fa3%40isocpp.org.
------=_Part_2793_825116473.1490577125313
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, March 26, 2017 at 6:11:08 PM UTC-4, Sea=
n Middleditch wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div><div class=3D"gmail_quote">On Fri, Mar 24, 2017 at 3:25 PM, N=
icol Bolas <span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" =
gdf-obfuscated-mailto=3D"4ZU9vxs4BwAJ" rel=3D"nofollow" onmousedown=3D"this=
..href=3D'javascript:';return true;" onclick=3D"this.href=3D'jav=
ascript:';return true;">jmck...@gmail.com</a>></span> wrote:<br><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"><span><blockquote class=3D"gmai=
l_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pad=
ding-left:1ex"><div dir=3D"ltr"><div><br></div><div>Basically, you want to =
write something like:</div><div><br></div><div>=C2=A0 iterable<T&>=
; foo::get_things() { return make_iterable(_things, [](auto& p){ return=
*p; }); }<br></div><div><br></div><div></div></div></blockquote></span><di=
v><br>That's a really bad tradeoff: type-erasing performance plus the c=
ost of filtering, all just to gain some increased genericity. <br></div></d=
iv></blockquote><div><br></div><div>Not at all, because that'd be a tem=
plate that gets fully inlined and result in identical machine code (assumin=
g a suitably capable optimizer).</div></div></div></div></blockquote><div><=
br>How? `iterable` doesn't specify the type of iterator used to iterate=
over `_things`, nor does it specify the type of range that `_things` is. B=
ut it still has to store either the range or an iterator pair over that ran=
ge. Therefore, the storage for those things must be type-erased in some fas=
hion. And that requires some form of indirect call to move to the next item=
in the iterator, as well as to call the functor. Not to mention having to =
type-erase the functor itself.<br><br>And type-erasure is the enemy of inli=
ning.<br><br>If that were an `iterable<span<T>, function_type>`=
, then I could buy the inlining. But not so long as type erasure has to be =
used.</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/0d3f5162-b2f9-4389-a0ec-4e3928492fa3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0d3f5162-b2f9-4389-a0ec-4e3928492fa3=
%40isocpp.org</a>.<br />
------=_Part_2793_825116473.1490577125313--
------=_Part_2792_1819910155.1490577125313--
.
Author: Sean Middleditch <sean.middleditch@gmail.com>
Date: Sun, 26 Mar 2017 20:59:56 -0700
Raw View
--94eb2c060d025dda68054bae6056
Content-Type: text/plain; charset=UTF-8
On Mar 26, 2017 6:12 PM, "Nicol Bolas" <jmckesson@gmail.com> wrote:
On Sunday, March 26, 2017 at 6:11:08 PM UTC-4, Sean Middleditch wrote:
> On Fri, Mar 24, 2017 at 3:25 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>
>>
>>> Basically, you want to write something like:
>>>
>>> iterable<T&> foo::get_things() { return make_iterable(_things,
>>> [](auto& p){ return *p; }); }
>>>
>>>
>> That's a really bad tradeoff: type-erasing performance plus the cost of
>> filtering, all just to gain some increased genericity.
>>
>
> Not at all, because that'd be a template that gets fully inlined and
> result in identical machine code (assuming a suitably capable optimizer).
>
How? `iterable` doesn't specify the
It's an expositional snippet. This might shock and surprise you, but it
wasn't copied verbatim from a working "thingy" codebase I just had lying
around. :)
I expect that `Iterator` could be defined as a concept in C++2x. The C++14
template version should use `auto` as the return value, yes. My mistake.
Thanks for the totally necessary lesson on runtime abstraction costs though.
--
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/nc5Sj-LtKbA/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/0d3f5162-b2f9-4389-
a0ec-4e3928492fa3%40isocpp.org
<https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/0d3f5162-b2f9-4389-a0ec-4e3928492fa3%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/CALQmNFiye2%3D681BUYyrYXhhYd-ub0X%3DQu0LaOqoj-2YLApFCKQ%40mail.gmail.com.
--94eb2c060d025dda68054bae6056
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div><div class=3D"gmail_extra"><div class=3D"gmail_quote=
">On Mar 26, 2017 6:12 PM, "Nicol Bolas" <<a href=3D"mailto:jm=
ckesson@gmail.com">jmckesson@gmail.com</a>> wrote:<br type=3D"attributio=
n"><blockquote class=3D"quote" style=3D"margin:0 0 0 .8ex;border-left:1px #=
ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><br>On Sunday, March 26, 2=
017 at 6:11:08 PM UTC-4, Sean Middleditch wrote:<div class=3D"quoted-text">=
<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;borde=
r-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D=
"gmail_quote">On Fri, Mar 24, 2017 at 3:25 PM, Nicol Bolas <span dir=3D"ltr=
"><<a rel=3D"nofollow">jmck...@gmail.com</a>></span> wrote:<br><block=
quote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc=
solid;padding-left:1ex"><div dir=3D"ltr"><span><blockquote class=3D"gmail_=
quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;paddi=
ng-left:1ex"><div dir=3D"ltr"><div><br></div><div>Basically, you want to wr=
ite something like:</div><div><br></div><div>=C2=A0 iterable<T&> =
foo::get_things() { return make_iterable(_things, [](auto& p){ return *=
p; }); }<br></div><div><br></div><div></div></div></blockquote></span><div>=
<br>That's a really bad tradeoff: type-erasing performance plus the cos=
t of filtering, all just to gain some increased genericity. <br></div></div=
></blockquote><div><br></div><div>Not at all, because that'd be a templ=
ate that gets fully inlined and result in identical machine code (assuming =
a suitably capable optimizer).</div></div></div></div></blockquote></div><d=
iv><br>How? `iterable` doesn't specify the</div></div></blockquote></di=
v></div></div><div dir=3D"auto"><br></div><div dir=3D"auto">It's an exp=
ositional snippet. This might shock and surprise you, but it wasn't cop=
ied verbatim from a working "thingy" codebase I just had lying ar=
ound. :)</div><div dir=3D"auto"><br></div><div dir=3D"auto">I expect that `=
Iterator` could be defined as a concept in C++2x. The C++14 template versio=
n should use `auto` as the return value, yes. My mistake.</div><div dir=3D"=
auto"><br></div><div dir=3D"auto">Thanks for the totally necessary lesson o=
n runtime abstraction costs though.</div><div dir=3D"auto"><br></div><div d=
ir=3D"auto"><div class=3D"gmail_extra"><div class=3D"gmail_quote"><blockquo=
te class=3D"quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr"><br></div><div class=3D"quoted-text">
<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/nc5Sj-LtKbA/unsubscribe" target=3D"_blan=
k">https://groups.google.com/a/<wbr>isocpp.org/d/topic/std-<wbr>proposals/n=
c5Sj-LtKbA/<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></div>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0d3f5162-b2f9-4389-a0ec-4e3928492fa3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/0d3f=
5162-b2f9-4389-<wbr>a0ec-4e3928492fa3%40isocpp.org</a><wbr>.<br>
</blockquote></div><br></div></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/CALQmNFiye2%3D681BUYyrYXhhYd-ub0X%3DQ=
u0LaOqoj-2YLApFCKQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALQmNFiye2%3=
D681BUYyrYXhhYd-ub0X%3DQu0LaOqoj-2YLApFCKQ%40mail.gmail.com</a>.<br />
--94eb2c060d025dda68054bae6056--
.