Topic: auto qualifiers


Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Thu, 9 Jul 2015 20:22:25 -0700 (PDT)
Raw View
------=_Part_1558_1913941356.1436498545982
Content-Type: multipart/alternative;
 boundary="----=_Part_1559_775296536.1436498545983"

------=_Part_1559_775296536.1436498545983
Content-Type: text/plain; charset=UTF-8

Writing getters and setters for simple classes has a lot of redundancy with
references and const

class vec2 {
  public:
    auto& x() { return _v[0]; }
    const auto& x() const { return _v[0]; }
    auto& y() { return _v[1]; }
    const auto& y() const { return _v[1]; }
  private:
    double _v[2];
};


We could use the auto keyword in place of const to vary on cv qualifiers,
and auto&& to also vary on reference qualifiers for automatic perfect
forwarding.

class vec3 {
  public:
    //Generates templates for vec3, const vec3, volatile vec3, const
volatile vec3
    auto x() auto { return _v[0]; }
    //Generates templates for the above, constrained to lvalue this
    auto& y() auto& { return _v[1]; }
    //Generates templates for the above, with overloads for rvalue this,
enables perfect forwarding
    auto&& z() auto&& { return std::forward<std::thisref_t>(_v[2]); }
  private:
    double _v[3];
};

Unfortunately, the this pointer doesn't carry over the lvalue or rvalueness
of the this object. We have to introduce new machinery to get this
information.
We can introduce a magic type struct std::thisref_t and a magic global
variable std::thisref_t std::thisref.
- static std::thisref_t std::thisref will be a global variable reference to
the "this" object with the correct cv and ref qualifiers.
- If the member function context has no ref qualifier, std::thisref_t is an
lvalue reference type with cv qualifiers if any.
- std::thisref is usable in constexpr context.
- If this is captured within a lambda, std::thisref and std::thisref_t will
be valid within the context of the lambda function body and refer to the
outer class scope this object.
- Refering to std::thisref_t or std::thisref outside of a class scope is
ill formed.


--

---
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_1559_775296536.1436498545983
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Writing getters and setters for simple classes has a lot o=
f redundancy with references and const<div><br><div><div class=3D"prettypri=
nt" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; b=
ackground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div clas=
s=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
vec2 </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 </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">public</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D"colo=
r: #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"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> _v</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</sp=
an><span style=3D"color: #066;" class=3D"styled-by-prettify">0</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;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">const</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">&amp;</span><font color=3D"#000000"><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> x</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">const</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> _v</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #066;=
" class=3D"styled-by-prettify">0</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"><b=
r></span></font><span style=3D"color: #000;" class=3D"styled-by-prettify">=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">auto</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&a=
mp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> y</spa=
n><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: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">return</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: #066;" class=3D"styled-by-prett=
ify">1</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 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&amp;</span><font color=3D"#000000"><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> y</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </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: #008;" class=3D"styled-by-prettify">re=
turn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> _v</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span=
 style=3D"color: #066;" class=3D"styled-by-prettify">1</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;" cl=
ass=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></font><font color=3D"#000000"><span style=3D"=
color: #000;" class=3D"styled-by-prettify">=C2=A0 </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">private</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 </span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">double</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> _v</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">[</span><span style=3D"color: #066;" class=3D"styl=
ed-by-prettify">2</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">];</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></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 </sp=
an></font></div></code></div><div><br></div>We could use the auto keyword i=
n place of const to vary on cv qualifiers, and auto&amp;&amp; to also vary =
on reference qualifiers for automatic perfect forwarding.</div><div><br></d=
iv><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"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> vec3 </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">public</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-=
by-prettify">//Generates templates for vec3, const vec3, volatile vec3, con=
st volatile vec3</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> x</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"styled-by-prettify">auto</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: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">return</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: #066;" class=3D"styled-by-prett=
ify">0</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 </span><sp=
an style=3D"color: #800;" class=3D"styled-by-prettify">//Generates template=
s for the above, constrained to lvalue this</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><font color=3D"#000000"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span></f=
ont><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> y</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;" cla=
ss=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&amp;</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: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</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: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">];</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </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></span><font color=3D"#000000"><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"color: #800;"=
 class=3D"styled-by-prettify">//Generates templates for the above, with ove=
rloads for rvalue this, enables perfect forwarding</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span></font><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> z</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">auto</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&amp;&amp;</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"> </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">forward</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">thisref_t</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">_v</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">[</span><font color=3D"#006666"><span style=3D"color: #066;" class=3D"sty=
led-by-prettify">2</span></font><span style=3D"color: #660;" class=3D"style=
d-by-prettify">]);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
</span><font color=3D"#000000"><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span></font><span style=3D"color: #000;" class=3D"style=
d-by-prettify">=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">private</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">double</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> _v</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</=
span><font color=3D"#006666"><span style=3D"color: #066;" class=3D"styled-b=
y-prettify">3</span></font><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></span><=
/div></code></div><br>Unfortunately, the this pointer doesn&#39;t carry ove=
r the lvalue or rvalueness of the this object. We have to introduce new mac=
hinery to get this information.=C2=A0</div><div>We can introduce a magic ty=
pe struct std::thisref_t and a magic global variable std::thisref_t std::th=
isref.=C2=A0</div><div>- static std::thisref_t std::thisref will be a globa=
l variable reference to the &quot;this&quot; object with the correct cv and=
 ref qualifiers.</div><div>- If the member function context has no ref qual=
ifier, std::thisref_t is an lvalue reference type with cv qualifiers if any=
..=C2=A0</div><div>- std::thisref is usable in constexpr context.=C2=A0</div=
><div>- If this is captured within a lambda, std::thisref and std::thisref_=
t will be valid within the context of the lambda function body and refer to=
 the outer class scope this object.</div><div>- Refering to std::thisref_t =
or std::thisref outside of a class scope is ill formed.</div><div><br><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&quot; 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_1559_775296536.1436498545983--
------=_Part_1558_1913941356.1436498545982--

.


Author: David Krauss <potswa@gmail.com>
Date: Fri, 10 Jul 2015 12:17:41 +0800
Raw View
--Apple-Mail=_10120CCD-268C-44E9-856F-4CB399D2657C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

I plan to cover this in the next revision of generalized lifetime extension=
: http://bit.ly/genlife <http://bit.ly/genlife> (pdf)

The syntax would be: auto & x() export( const && ) { return _v[ 0 ]; }

The export keyword after the parameter list signifies that the return value=
 references this. (It =E2=80=9Cexports=E2=80=9D properties from the object =
to the caller.) The idea is that most (if not all) cases of functions with =
similar bodies and covariance of constness and value category are propertie=
s: The object (*this) needs lifetime extension if the return value is bound=
 to a non-temporary reference.

I don=E2=80=99t plan anything like thisref. The return value is simply requ=
ired to be an lvalue, and then treated as an xvalue if the transformation o=
f the return type results in an rvalue reference.

Note, there=E2=80=99s some trickiness with members of reference type:

template< typename obj_or_ref >
class wrap {
    obj_or_ref a;
public:
    obj_or_ref & get() export( const && ) { return a; }
};

If obj_or_ref is a reference type T&, get()&& should still return an lvalue=
.. In this case, reference collapsing produces T & && =3D T &. (However, if =
obj_or_ref is an rvalue reference type, calling the function on an rvalue w=
rap does produce an xvalue via T && && =3D T &&.)


> On 2015=E2=80=9307=E2=80=9310, at 11:22 AM, Matthew Fioravante <fmatthew5=
876@gmail.com> wrote:
>=20
>     auto&& z() auto&& { return std::forward<std::thisref_t>(_v[2]); }

This is incomplete, by the way. You need std::forward<std::thisref_t>(*this=
)._v[2];. You also propose thisref.v[2], but I think it=E2=80=99s dangerous=
 to get an rvalue expression so easily. A programmer could get in the habit=
 of sprinkling thisref everywhere, not realizing that it combines with auto=
&& to create implicit moves.

--=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/.

--Apple-Mail=_10120CCD-268C-44E9-856F-4CB399D2657C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><div class=3D"">I =
plan to cover this in the next revision of generalized lifetime extension:&=
nbsp;<a href=3D"http://bit.ly/genlife" class=3D"">http://bit.ly/genlife</a>=
&nbsp;(pdf)</div><div class=3D""><br class=3D""></div><div class=3D"">The s=
yntax would be:&nbsp;<font face=3D"Courier" class=3D"">auto &amp; x() expor=
t( const &amp;&amp; ) { return _v[ 0 ]; }</font></div><div class=3D""><br c=
lass=3D""></div><div class=3D"">The <font face=3D"Courier" class=3D"">expor=
t</font>&nbsp;keyword after the parameter list signifies that the return va=
lue references <font face=3D"Courier" class=3D"">this</font>. (It =E2=80=9C=
exports=E2=80=9D properties from the object to the caller.) The idea is tha=
t most (if not all) cases of functions with similar bodies and covariance o=
f constness and value category are properties: The object (<font face=3D"Co=
urier" class=3D"">*this</font>) needs lifetime extension if the return valu=
e is bound to a non-temporary reference.</div><div class=3D""><br class=3D"=
"></div><div class=3D"">I don=E2=80=99t plan anything like <font face=3D"Co=
urier" class=3D"">thisref</font>. The return value is simply required to be=
 an lvalue, and then treated as an xvalue if the transformation of the retu=
rn type results in an rvalue reference.</div><div class=3D""><br class=3D""=
></div><div class=3D"">Note, there=E2=80=99s some trickiness with members o=
f reference type:</div><div class=3D""><br class=3D""></div><div class=3D""=
><font face=3D"Courier" class=3D"">template&lt; typename obj_or_ref &gt;</f=
ont></div><div class=3D""><font face=3D"Courier" class=3D"">class wrap {</f=
ont></div><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp;&n=
bsp;obj_or_ref&nbsp;a;</font></div><div class=3D""><font face=3D"Courier" c=
lass=3D"">public:</font></div><div class=3D""><font face=3D"Courier" class=
=3D"">&nbsp; &nbsp;&nbsp;obj_or_ref&nbsp;&amp; get() export( const &amp;&am=
p; ) { return a; }</font></div><div class=3D""><font face=3D"Courier" class=
=3D"">};</font></div><div class=3D""><br class=3D""></div><div class=3D"">I=
f <font face=3D"Courier" class=3D"">obj_or_ref</font> is a reference type <=
font face=3D"Courier" class=3D"">T&amp;</font>, <font face=3D"Courier" clas=
s=3D"">get()&amp;&amp;</font> should still return an lvalue. In this case, =
reference collapsing produces <font face=3D"Courier" class=3D"">T &amp; &am=
p;&amp;</font> =3D <font face=3D"Courier" class=3D"">T &amp;</font>. (Howev=
er, if <font face=3D"Courier" class=3D"">obj_or_ref</font> is an rvalue ref=
erence type, calling the function on an rvalue <font face=3D"Courier" class=
=3D"">wrap</font> does produce an xvalue via <font face=3D"Courier" class=
=3D"">T &amp;&amp; &amp;&amp;</font> =3D <font face=3D"Courier" class=3D"">=
T &amp;&amp;</font>.)</div><div class=3D""><br class=3D""></div><br class=
=3D""><div><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=
=80=9307=E2=80=9310, at 11:22 AM, Matthew Fioravante &lt;<a href=3D"mailto:=
fmatthew5876@gmail.com" class=3D"">fmatthew5876@gmail.com</a>&gt; wrote:</d=
iv><br class=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr"=
 class=3D""><div class=3D""><div class=3D""><div class=3D"prettyprint" styl=
e=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgroun=
d-color: rgb(250, 250, 250);">&nbsp; &nbsp;&nbsp;<span class=3D"styled-by-p=
rettify" style=3D"color: rgb(0, 0, 136);">auto</span><span class=3D"styled-=
by-prettify" style=3D"color: rgb(102, 102, 0);">&amp;&amp;</span> z<span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">()</span> <sp=
an class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">auto</span=
><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">&amp=
;&amp;</span> <span class=3D"styled-by-prettify" style=3D"color: rgb(102, 1=
02, 0);">{</span> <span class=3D"styled-by-prettify" style=3D"color: rgb(0,=
 0, 136);">return</span> std<span class=3D"styled-by-prettify" style=3D"col=
or: rgb(102, 102, 0);">::</span>forward<span class=3D"styled-by-prettify" s=
tyle=3D"color: rgb(102, 102, 0);">&lt;</span>std<span class=3D"styled-by-pr=
ettify" style=3D"color: rgb(102, 102, 0);">::</span>thisref_t<span class=3D=
"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">&gt;(</span>_v<span=
 class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">[</span><f=
ont color=3D"#006666" class=3D"">2</font><span class=3D"styled-by-prettify"=
 style=3D"color: rgb(102, 102, 0);">]);</span> <span class=3D"styled-by-pre=
ttify" style=3D"color: rgb(102, 102, 0);">}</span></div></div></div></div><=
/div></blockquote><div><br class=3D""></div><div>This is incomplete, by the=
 way. You need&nbsp;<font face=3D"Courier" class=3D""><span style=3D"backgr=
ound-color: rgb(250, 250, 250);" class=3D"">std</span><span class=3D"styled=
-by-prettify">::</span><span style=3D"background-color: rgb(250, 250, 250);=
" class=3D"">forward</span><span class=3D"styled-by-prettify">&lt;</span><s=
pan style=3D"background-color: rgb(250, 250, 250);" class=3D"">std</span><s=
pan class=3D"styled-by-prettify">::</span><span style=3D"background-color: =
rgb(250, 250, 250);" class=3D"">thisref_t</span><span class=3D"styled-by-pr=
ettify">&gt;(*this).</span><span style=3D"background-color: rgb(250, 250, 2=
50);" class=3D"">_v</span><span class=3D"styled-by-prettify">[</span><font =
class=3D"">2</font></font><span class=3D"styled-by-prettify"><font face=3D"=
Courier" class=3D"">];</font><span style=3D"background-color: rgb(250, 250,=
 250);" class=3D"">. You also propose&nbsp;<font face=3D"Courier" class=3D"=
">thisref.v[2]</font>, but I think it=E2=80=99s dangerous to get an rvalue =
expression so easily. A programmer could get in the habit of sprinkling <fo=
nt face=3D"Courier" class=3D"">thisref</font> everywhere, not realizing tha=
t it combines with <font face=3D"Courier" class=3D"">auto&amp;&amp;</font> =
to create implicit moves.</span></span></div></div><br class=3D""></body></=
html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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 />

--Apple-Mail=_10120CCD-268C-44E9-856F-4CB399D2657C--

.