Topic: Mid expression statements
Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Thu, 4 Dec 2014 20:04:02 +0000
Raw View
Gcc has the syntax ({ }) to embed a statement block within an
expression. Should this be standardised?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: gmisocpp@gmail.com
Date: Thu, 4 Dec 2014 14:03:18 -0800 (PST)
Raw View
------=_Part_893_33065169.1417730598113
Content-Type: multipart/alternative;
boundary="----=_Part_894_1675514457.1417730598113"
------=_Part_894_1675514457.1417730598113
Content-Type: text/plain; charset=UTF-8
On Friday, December 5, 2014 9:04:03 AM UTC+13, Douglas Boffey wrote:
>
> Gcc has the syntax ({ }) to embed a statement block within an
> expression. Should this be standardised?
>
I assume you are referring to this feature:
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
I wasn't previously aware it until reading your post.
The examples I see though do seem to produce some pretty unreadable code.
Don't you think?
What the main reason for standardising this, is it to gain more
compatibility with C, or is it more because it's useful in it's own right?
it'd be nice to have examples of it's use that show when using it is
the best solution.
Slightly related, I was also just reading this blog about using C++ code to
manage C code:
https://dun.gs/posts/2014-11-06-c-cpp-memory.html
It concludes that using certain C interfaces in C++ makes this necessary:
using uniqueRepositoryPtr = std::unique_ptr<git_repository, decltype
(&git_repository_free)>;
git_repository *rawRepo = nullptr;
git_repository_open(&rawRepo, "./testrepo");
uniqueRepositoryPtr repo{std::move(rawRepo), git_repository_free};
Now I'm wondering if expression statements would help simplify the above
code?
I suspect the best solution for this example though is some more specific
C++ RAII wrappers.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_894_1675514457.1417730598113
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br>On Friday, December 5, 2014 9:04:03 AM UTC+13, Douglas=
Boffey wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0p=
x 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-l=
eft-width: 1px; border-left-style: solid;">Gcc has the syntax ({ }) to embe=
d a statement block within an
<br>expression. Should this be standardised?
<br></blockquote><div><br></div><div>I assume you are referring to this fea=
ture:</div><div><a href=3D"https://gcc.gnu.org/onlinedocs/gcc/Statement-Exp=
rs.html">https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html</a></div><=
div>I wasn't previously aware it until reading your post.</div><div><br></d=
iv><div>The examples I see though do seem to produce some pretty unrea=
dable code. Don't you think?</div><div><br></div><div>What the main reason =
for standardising this, is it to gain more compatibility with C, or is it m=
ore because it's useful in it's own right?</div><div><br></div><div><div>it=
'd be nice to have examples of it's use that show when using it is the=
best solution.</div></div><div><br></div><div>Slightly related, =
I was also just reading this blog about using C++ =
code to manage C code:</div><div><a href=3D"https://dun.gs/posts/=
2014-11-06-c-cpp-memory.html">https://dun.gs/posts/2014-11-06-c-cpp-memory.=
html</a></div><div>It concludes that using certain C interfaces in C++ make=
s this necessary:</div><div><span class=3D"kw">using</span> uniqueRepositor=
yPtr =3D std::unique_ptr<git_repository, <span class=3D"kw">decltype</sp=
an>(&git_repository_free)>;<br> git_repository *ra=
wRepo =3D <span class=3D"kw">nullptr</span>;<br> git_repo=
sitory_open(&rawRepo, <span class=3D"st">"./testrepo"</span>);<br> =
; uniqueRepositoryPtr repo{std::move(rawRepo), git_repository_f=
ree};</div><div><br></div><div><div>Now I'm wondering if expression stateme=
nts would help simplify the above code?</div><div>I suspect the best s=
olution for this example though is some more specific C++ RAII wrappers.<br=
></div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_894_1675514457.1417730598113--
------=_Part_893_33065169.1417730598113--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Thu, 4 Dec 2014 14:31:16 -0800 (PST)
Raw View
------=_Part_1353_521945010.1417732276530
Content-Type: text/plain; charset=UTF-8
We have that already; it's spelt [&]{...}().
(Javascript calls these immediately invoked function expressions, or IIFEs; it would be good to have a well-recognized name for them in C++. My current preferred term is "immediate lambdas".)
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1353_521945010.1417732276530--
.
Author: Magnus Fromreide <magfr@lysator.liu.se>
Date: Thu, 4 Dec 2014 23:39:24 +0100
Raw View
On Thu, Dec 04, 2014 at 02:31:16PM -0800, Edward Catmur wrote:
> We have that already; it's spelt [&]{...}().
Not quite.
Statement expressions are not external from the function and so you can call
break, continue, goto and return from them but not from the lambda.
Note that this adds some complexity, what does it mean if the test in a while
loop calls break?
/MF
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.