Topic: Comment on proposed C++14 Standard (N3690,
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 7 Jul 2013 13:44:38 +0300
Raw View
--20cf3074d5c450619a04e0e99de1
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
On 7 July 2013 13:38, Mikhail Semenov <mikhailsemenov1957@gmail.com> wrote:
> Section 5.1.2, paragraph 3 reads:
>
> The type of the lambda-expression (which is also the type of the closure
> object) is a unique, unnamed non-union
> class type =97 called the closure type =97 whose properties are described
> below. This class type is not
> an aggregate (8.5.1). *The closure type is declared in the smallest block
> scope, class scope, or namespace
> scope that contains the corresponding lambda-expression.*
> Surely, a closure should be defined on the top level as most classes, in
> order to allow it to be safely returned from the function block,
>
Surely not. The declaration shouldn't magically move outside its block
scope just because it needs to be returned
from a function.
> so that the function return type is properly defined. Otherwise, if it's
> class is only defined in the corresponding function block, what will be t=
he
> return
> type of the function?
>
>
>
It's possible to have a return type that is declared inside a function. A
lambda is one example of it, returning an object
of local class type is another.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--20cf3074d5c450619a04e0e99de1
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 7 July 2013 13:38, Mikhail Semenov <span dir=3D"ltr"><<a href=
=3D"mailto:mikhailsemenov1957@gmail.com" target=3D"_blank">mikhailsemenov19=
57@gmail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><p>Section 5.1.2, paragraph 3 reads:</p><p><=
font color=3D"#0000ff" face=3D"georgia,serif">The type of the lambda-expres=
sion (which is also the type of the closure object) is a unique, unnamed no=
n-union<br>
class type =97 called the closure type =97 whose properties are described b=
elow. This class type is not<br>an aggregate (8.5.1). </font><b><font color=
=3D"#0000ff" face=3D"georgia,serif">The closure type is declared in the sma=
llest block scope, class scope, or namespace<br>
scope that contains the corresponding lambda-expression.</font></b></p><div=
>Surely, a closure should be defined on the top level as most classes, in o=
rder to allow it to be safely returned from the function block,<br></div>
</blockquote><div><br></div><div>Surely not. The declaration shouldn't =
magically move outside its block scope just because it needs to be returned=
<br>from a function.<br>=A0<br></div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>so that the function return type is properly defined. Otherwise, if it=
's class is only defined in=A0the corresponding=A0function block, what =
will be the return</div><div>type of the function?</div><span class=3D"HOEn=
Zb"><font color=3D"#888888"><div>
<br><br></div></font></span></blockquote><div><br></div><div>It's possi=
ble to have a return type that is declared inside a function. A lambda is o=
ne example of it, returning an object<br>of local class type is another. <b=
r>
</div></div><br></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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
--20cf3074d5c450619a04e0e99de1--
.
Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sun, 7 Jul 2013 04:06:48 -0700 (PDT)
Raw View
------=_Part_8296_971977.1373195208706
Content-Type: text/plain; charset=ISO-8859-1
>It's possible to have a return type that is declared inside a function. A
lambda is one example of it, returning an object
>of local class type is another.
Ville,
Could, you explain to me, please, what happens to auto variable in such
cases (when a value of the local class is returned from a function)?
*
auto x = f();
*
Mikhail.
--
---
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_8296_971977.1373195208706
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div><br><font style=3D"background-color: rgb(0, 0, 255);"><font color=3D"#=
0000ff" style=3D"background-color: rgb(255, 255, 255);">>It's possible t=
o have a return type that is declared inside a function. A lambda is one ex=
ample of it, returning an object<br>>of local class type is another. </f=
ont></font></div><font style=3D"background-color: rgb(0, 0, 255);"><font co=
lor=3D"#0000ff" style=3D"background-color: rgb(255, 255, 255);"><p> </=
p><font color=3D"#000000">Ville, </font></font></font><div><font style=3D"b=
ackground-color: rgb(255, 255, 255);">Could, you explain to me, please, wha=
t happens to auto variable in such cases (when a value of the local class i=
s returned from a function)?</font></div><div> </div><div></div><stron=
g><div>auto x =3D f();</div><div><br> </div></strong><div>
Mikhail.</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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
------=_Part_8296_971977.1373195208706--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 7 Jul 2013 14:10:34 +0300
Raw View
--001a11c2c0ec1a598404e0e9fa64
Content-Type: text/plain; charset=ISO-8859-1
On 7 July 2013 14:06, Mikhail Semenov <mikhailsemenov1957@gmail.com> wrote:
>
> >It's possible to have a return type that is declared inside a function. A
> lambda is one example of it, returning an object
> >of local class type is another.
>
>
> Ville,
> Could, you explain to me, please, what happens to auto variable in such
> cases (when a value of the local class is returned from a function)?
>
> *
> auto x = f();
>
>
> *
The type of the variable is the type returned from the function. You can't
name such a type, but with auto,
you can use it. "It just works", I guess.
--
---
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/.
--001a11c2c0ec1a598404e0e9fa64
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 7 July 2013 14:06, Mikhail Semenov <span dir=3D"ltr"><<a href=
=3D"mailto:mikhailsemenov1957@gmail.com" target=3D"_blank">mikhailsemenov19=
57@gmail.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div class=3D"im"><div><br><font style=3D"ba=
ckground-color:rgb(0,0,255)"><font style=3D"background-color:rgb(255,255,25=
5)" color=3D"#0000ff">>It's possible to have a return type that is d=
eclared inside a function. A lambda is one example of it, returning an obje=
ct<br>
>of local class type is another. </font></font></div></div><font style=
=3D"background-color:rgb(0,0,255)"><font style=3D"background-color:rgb(255,=
255,255)" color=3D"#0000ff"><p>=A0</p><font color=3D"#000000">Ville, </font=
></font></font><div>
<font style>Could, you explain to me, please, what happens to auto variable=
in such cases (when a value of the local class is returned from a function=
)?</font></div><div>=A0</div><div></div><b><div>auto x =3D f();</div><span =
class=3D"HOEnZb"><font color=3D"#888888"><div>
<br><br></div></font></span></b></blockquote><div><br></div><div>The type o=
f the variable is the type returned from the function. You can't name s=
uch a type, but with auto,<br>you can use it. "It just works", I =
guess. <br>
</div></div><br></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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
--001a11c2c0ec1a598404e0e9fa64--
.
Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sun, 7 Jul 2013 04:51:05 -0700 (PDT)
Raw View
------=_Part_4625_28631858.1373197865846
Content-Type: text/plain; charset=ISO-8859-1
>The type of the variable is the type returned from the function. You can't
name such a type, but with auto,
>you can use it. "It just works", I guess.
(1) The lambda type is anonymous anyway, so there is no issue whether it is
global or local in this respect.
(2) But, there IS an issue with objects that are not odr-used, they can be
accessed without being captured, like
in the following example (from the proposed C++ Standard):
*void f1(int i) {
int const N = 20;
auto m1 = [=]{
int const M = 30;
auto m2 = [i]{
int x[N][M]; // OK: N and M are not odr-used
x[0][0] = i; // OK: i is explicitly captured by m2
// and implicitly captured by m1
};
}*
**
I guess in this case, lambda class can only be local to access N and M
values. I personally think that *named access* and the requirement to
capture
all the values (except global ones) inside the lambda captures would be a
better approach. The ord-used issue is a rather grey area.
(3) There is another discussion
https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-proposals/6Mp0OUawJ8M
which shows that there is an issue with associated name spaces for lambda.
--
---
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_4625_28631858.1373197865846
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div><font color=3D"#0000ff">>The type of the variable is the type retur=
ned from the function. You can't name such a type, but with auto,<br>>yo=
u can use it. "It just works", I guess. </font></div><div><font color=3D"#0=
000ff"></font> </div><div><font color=3D"#000000">(1) The lambda type =
is anonymous anyway, so there is no issue whether it is global or local in =
this respect.</font></div><div><font color=3D"#000000">(2) But, there IS&nb=
sp;an issue with objects that are not odr-used, they can be acces=
sed without being captured, like</font></div><div><font color=3D"#000000">i=
n the following example (from the proposed C++ Standard):</font></div><div>=
</div><div><font face=3D"courier new,monospace"><strong>void f1(int i=
) {<br> int const N =3D 20;<br> auto m1 =3D [=3D]{<=
br> int const M =3D 30;<br> auto m2 =3D [i]{<br>&nb=
sp; int x[N][M]; // OK: N and M are not odr-used<br> =
; x[0][0] =3D i; // OK: i is explicitly captured by m2<br=
> &n=
bsp; // and implicitly captured by m1<br> &nbs=
p; };<br>}</strong></font></div><div><strong><font face=3D"Courier New"></f=
ont></strong> </div><div><font face=3D"arial,sans-serif">I guess in th=
is case, lambda class can only be local to access N and M values. I persona=
lly think that <strong><font color=3D"#9900ff">named access</font></strong>=
and the requirement to capture</font></div><div><font color=3D"#9900ff">al=
l the values (except global ones)</font> inside the lambda captures would b=
e a better approach. The ord-used issue is a rather grey area.</div><div>&n=
bsp;</div><div>(3) There is another discussion </div><div><a href=3D"https:=
//groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-proposals/6Mp=
0OUawJ8M">https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/s=
td-proposals/6Mp0OUawJ8M</a></div><div>which shows that there is an issue w=
ith associated name spaces for lambda.</div><div> </div><div> </d=
iv><div> </div><div> </div><div> </div><div> </div><div=
><br><br> </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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
------=_Part_4625_28631858.1373197865846--
.