Topic: N3748: Implicit Evaluation of auto Variables and Arguments
Author: jgottman6@gmail.com
Date: Wed, 4 Sep 2013 19:30:01 -0700 (PDT)
Raw View
------=_Part_6340_24743556.1378348201875
Content-Type: text/plain; charset=ISO-8859-1
Paper N3748 (Implicit Evaluation of auto Variables and Arguments<https://groups.google.com/a/isocpp.org/forum/?fromgroups#!newtopic/std-proposals>)
proposes an "operator auto" to handle the problems that auto has with
expression templates and similar classes. If a class Foo defines a member
function operator auto() returning type Bar, then in the code
Foo foo;
auto x = foo;
the type of x would be Bar and not Foo. While I think this a good idea, I
think that there are some items that are missing:
1) How does this interact with the C++14 decltype(auto) construct? I would
expect the code
decltype(auto) y = foo;
to actually declare an object of type Foo, despite the existence of the
operator auto() function. The paper currently uses "explicit auto" to
disable operator auto, but using decltype(auto) for this would fit in
better with existing rules.
2) How does this interact with return-type deduction in lambdas and normal
functions? If you have a function
auto myFunc() -> auto {Foo foo; return foo;}
is the return type of myFunc() Foo or Bar?
3) Would it be possible to overload operator auto() on the constness or
rvalue-ness of *this? Something like
Bar operator auto() const & {return Bar(*this);} // copy lvalues
Bar operator auto() && {return Bar(move(*this)); } // move rvalues
Joe Gottman
--
---
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_6340_24743556.1378348201875
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Paper N3748 (<a href=3D"https://groups.google.com/a/isocpp=
..org/forum/?fromgroups#!newtopic/std-proposals">Implicit Evaluation of auto=
Variables and Arguments</a>) proposes an "operator auto" to handle the pro=
blems that auto has with expression templates and similar classes. If=
a class Foo defines a member function operator auto() returning type Bar, =
then in the code<br><br><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">Foo</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> foo</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: #008;" class=3D"styled-by-prettify">auto</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> x </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span></div></code></div><br>the type of x wo=
uld be Bar and not Foo. While I think this a good idea, I think that =
there are some items that are missing:<br><br>1) How does this interact wit=
h the C++14 decltype(auto) construct? I would expect the code<br><div=
class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); borde=
r-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-w=
rap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><span style=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> y </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span></div></code></div><br>to actually declare an object of type=
Foo, despite the existence of the operator auto() function. The pape=
r currently uses "explicit auto" to disable operator auto, but using declty=
pe(auto) for this would fit in better with existing rules.<br><br>2) =
How does this interact with return-type deduction in lambdas and normal fun=
ctions? If you have a function<br><br><div class=3D"prettyprint" styl=
e=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187)=
; border-style: solid; border-width: 1px; word-wrap: break-word;"><code cla=
ss=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008=
;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> myFunc</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </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: #008;" class=3D"styled-by-prettify">auto</s=
pan><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: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> foo</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: #008;" class=3D"style=
d-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> foo</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span></div></code></div><br>is the return type of myFunc() Foo or Bar?<b=
r><br><br>3) Would it be possible to overload operator auto() on the constn=
ess or rvalue-ness of *this? Something like<br><br><br><div class=3D"=
prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: r=
gb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: break=
-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Bar</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">operator</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">auto</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: #008;" class=3D"styled-by-prettify"=
>const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><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"colo=
r: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">Bar</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(*</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">this</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">);}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #800;" class=3D"styled-by-prettify">// copy lva=
lues</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Bar</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">auto</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"style=
d-by-prettify">&&</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">{</span><span style=3D"color: #008;" class=3D"styled-by-prettify">ret=
urn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">Bar</span><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: #008;" =
class=3D"styled-by-prettify">this</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: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// move rv=
alues</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
/span></div></code></div><br><br>Joe Gottman<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 />
------=_Part_6340_24743556.1378348201875--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 5 Sep 2013 02:33:40 -0700 (PDT)
Raw View
------=_Part_1321_21349954.1378373620722
Content-Type: text/plain; charset=ISO-8859-1
On Wednesday, September 4, 2013 7:30:01 PM UTC-7, jgot...@gmail.com wrote:
>
> Paper N3748 (Implicit Evaluation of auto Variables and Arguments<https://groups.google.com/a/isocpp.org/forum/?fromgroups#!newtopic/std-proposals>)
> proposes an "operator auto" to handle the problems that auto has with
> expression templates and similar classes. If a class Foo defines a member
> function operator auto() returning type Bar, then in the code
>
> Foo foo;
> auto x = foo;
>
> the type of x would be Bar and not Foo. While I think this a good idea, I
> think that there are some items that are missing:
>
> 1) How does this interact with the C++14 decltype(auto) construct? I
> would expect the code
> decltype(auto) y = foo;
>
> to actually declare an object of type Foo, despite the existence of the
> operator auto() function. The paper currently uses "explicit auto" to
> disable operator auto, but using decltype(auto) for this would fit in
> better with existing rules.
>
That's... problematic. `decltype(auto)` has a very different set of type
deduction rules for expressions than `auto`. I wouldn't want to have to be
forced into the `decltype(auto)` syntax just to get a variable of the
actual expression's type.
That being said, `decltype(auto)` very much should deduce the actual type.
It just shouldn't be the *only* way to do so.
> 2) How does this interact with return-type deduction in lambdas and
> normal functions? If you have a function
>
> auto myFunc() -> auto {Foo foo; return foo;}
>
> is the return type of myFunc() Foo or Bar?
>
First, I'm fairly sure you don't need two autos there; I think that may be
a compile error in C++14.
As for the question, that will be dealt when as they clear up the
consistency issue brought up in the paper.
At present, the type deduction rules are shared among return values,
template arguments, and `auto varname=...` (minus the `initializer_list`
thing). The proposal in the paper states that it only affects `auto varname
= ` deduction syntax.
The paper states that this is still an outstanding issue. The paper as a
whole reads very much like a first draft and rough sketch, rather than a
real, fully-formed proposal. So I imagine a lot of things are very much in
the air. I'd treat it more like a starting point than an ending point.
3) Would it be possible to overload operator auto() on the constness or
> rvalue-ness of *this? Something like
>
> Bar operator auto() const & {return Bar(*this);} // copy lvalues
> Bar operator auto() && {return Bar(move(*this)); } // move rvalues
>
>
I see no reason why that shouldn't or couldn't be allowed. Though if it is
allowed, I would much rather the `= default` syntax to automatically
generate *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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1321_21349954.1378373620722
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Wednesday, September 4, 2013 7:30:01 PM UTC-7, jgot...@=
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"lt=
r">Paper N3748 (<a href=3D"https://groups.google.com/a/isocpp.org/forum/?fr=
omgroups#!newtopic/std-proposals" target=3D"_blank">Implicit Evaluation of =
auto Variables and Arguments</a>) proposes an "operator auto" to handle the=
problems that auto has with expression templates and similar classes. =
; If a class Foo defines a member function operator auto() returning type B=
ar, then in the code<br><br><div style=3D"background-color:rgb(250,250,250)=
;border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wra=
p:break-word"><code><div><span style=3D"color:#606">Foo</span><span style=
=3D"color:#000"> foo</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#008">auto</span><span styl=
e=3D"color:#000"> x </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> foo</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br></span></div></code></div><br>the type of x would be Ba=
r and not Foo. While I think this a good idea, I think that there are=
some items that are missing:<br><br>1) How does this interact with the C++=
14 decltype(auto) construct? I would expect the code<br><div style=3D=
"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-sty=
le:solid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"c=
olor:#008">decltype</span><span style=3D"color:#660">(</span><span style=3D=
"color:#008">auto</span><span style=3D"color:#660">)</span><span style=3D"c=
olor:#000"> y </span><span style=3D"color:#660">=3D</span><span style=3D"co=
lor:#000"> foo</span><span style=3D"color:#660">;</span><span style=3D"colo=
r:#000"><br></span></div></code></div><br>to actually declare an object of =
type Foo, despite the existence of the operator auto() function. The =
paper currently uses "explicit auto" to disable operator auto, but using de=
cltype(auto) for this would fit in better with existing rules.<br></div></b=
lockquote><div><br>That's... problematic. `decltype(auto)` has a very diffe=
rent set of type deduction rules for expressions than `auto`. I wouldn't wa=
nt to have to be forced into the `decltype(auto)` syntax just to get a vari=
able of the actual expression's type.<br><br>That being said, `decltype(aut=
o)` very much should deduce the actual type. It just shouldn't be the <i>on=
ly</i> way to do so.<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">2) How does this interact with return-type ded=
uction in lambdas and normal functions? If you have a function<br><br=
><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,1=
87);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><s=
pan style=3D"color:#008">auto</span><span style=3D"color:#000"> myFunc</spa=
n><span style=3D"color:#660">()</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">-></span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660">{</span><span style=3D"color:#606">Foo</span><span st=
yle=3D"color:#000"> foo</span><span style=3D"color:#660">;</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#008">return</span><span styl=
e=3D"color:#000"> foo</span><span style=3D"color:#660">;}</span><span style=
=3D"color:#000"><br></span></div></code></div><br>is the return type of myF=
unc() Foo or Bar?<br></div></blockquote><div><br>First, I'm fairly sure you=
don't need two autos there; I think that may be a compile error in C++14.<=
br><br>As for the question, that will be dealt when as they clear up the co=
nsistency issue brought up in the paper.<br><br>At present, the type deduct=
ion rules are shared among return values, template arguments, and `auto var=
name=3D...` (minus the `initializer_list` thing). The proposal in the paper=
states that it only affects `auto varname =3D ` deduction syntax.<br><br>T=
he paper states that this is still an outstanding issue. The paper as a who=
le reads very much like a first draft and rough sketch, rather than a real,=
fully-formed proposal. So I imagine a lot of things are very much in the a=
ir. I'd treat it more like a starting point than an ending point.<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">3) Would =
it be possible to overload operator auto() on the constness or rvalue-ness =
of *this? Something like<br><br><div style=3D"background-color:rgb(25=
0,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1p=
x;word-wrap:break-word"><code><div><span style=3D"color:#606">Bar</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">operator</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">auto</span><sp=
an style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">const</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">&</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">{</span><span style=3D"color:#008">return</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#606">Bar</span><span style=
=3D"color:#660">(*</span><span style=3D"color:#008">this</span><span style=
=3D"color:#660">);}</span><span style=3D"color:#000"> </span><span style=3D=
"color:#800">// copy lvalues</span><span style=3D"color:#000"><br></span><s=
pan style=3D"color:#606">Bar</span><span style=3D"color:#000"> </span><span=
style=3D"color:#008">operator</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#660">()</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">&&</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span=
style=3D"color:#008">return</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">Bar</span><span style=3D"color:#660">(</span><span st=
yle=3D"color:#000">move</span><span style=3D"color:#660">(*</span><span sty=
le=3D"color:#008">this</span><span style=3D"color:#660">));</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">}</span><span style=3D=
"color:#000"> </span><span style=3D"color:#800">// move rvalues</span><span=
style=3D"color:#000"><br></span></div></code></div><br></div></blockquote>=
<div><br>I see no reason why that shouldn't or couldn't be allowed. Though =
if it is allowed, I would much rather the `=3D default` syntax to automatic=
ally generate <i>both</i>.<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 />
------=_Part_1321_21349954.1378373620722--
.