Topic: Allow to access member typedefs of a type from a


Author: Walter Heisenbug <walter.heisenbug@outlook.com>
Date: Tue, 14 Mar 2017 18:03:02 +0000
Raw View
Currently to access a member type from a reference type means you have to d=
o all the dancing with removing the reference.=20

template<typename T>
void f(T&& x)
{
=C2=A0=C2=A0=C2=A0 typedef typename std::remove_reference_t<T>::member_type=
 mem;
=C2=A0=C2=A0=C2=A0 mem y;
=C2=A0=C2=A0=C2=A0 use(std::forward<T>(x), y);
}

This could be simplified, if we allow to access the member types of a type =
from a reference types:

template<typename T>
void f(T&& x)
{
    typedef typename T::member_type mem;
    mem y;
    use(std::forward<T>(x), y);
}

I'm not aware of any potential problems, since the reference types don't ha=
ve any member types, so there's no ambiguity with the existing code.=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/DM5PR2201MB151446C188D54CABB6E0FE9C87240%40DM5PR=
2201MB1514.namprd22.prod.outlook.com.

.


Author: Jakob Riedle <jakob.riedle@gmail.com>
Date: Thu, 20 Apr 2017 00:57:25 -0700 (PDT)
Raw View
------=_Part_1993_1787644953.1492675045360
Content-Type: multipart/alternative;
 boundary="----=_Part_1994_1935460801.1492675045360"

------=_Part_1994_1935460801.1492675045360
Content-Type: text/plain; charset=UTF-8

I quite like this idea and I had this problem myself. The reason why
compilers reject this code is because
'T is not a class, struct, or union type'. I don't know whether it is a
good idea to consider *reference to class *a *class type.*
It would be very misleading to do this if we allow references to class
types to be usable as if they were the referenced class:
struct A{};
struct B : A& {};

*References to objects* can be and are treated exactly like the referenced
object itself.
Note that this only concerns the *run-time*.
On the other hand a *reference type* is not a class, it is ... a reference.

IMHO it is very consequent, that e.g. T::r is not resolvable for T being a
reference type,
because its not a class, struct or union type.

Cheers
Jakob

--
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/23d75c32-3724-49fa-961a-cb4a2c7259b7%40isocpp.org.

------=_Part_1994_1935460801.1492675045360
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I quite like this idea and I had this problem myself. The =
reason why compilers reject this code is because<div>&#39;<span style=3D"ba=
ckground-color: rgb(245, 245, 245); color: rgb(51, 51, 51); font-family: Me=
nlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; font-size: 13.33=
33px; white-space: pre;">T is not a class, struct, or union type&#39;</span=
>. I don&#39;t know whether it is a good idea to consider <i>reference to c=
lass </i>a <i>class type.</i></div><div>It would be very misleading to do t=
his if we allow references to class types to be usable as if they were the =
referenced class:</div><div class=3D"prettyprint" style=3D"background-color=
: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid=
; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><d=
iv class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by=
-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> B </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{};</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span></div></code></div><div><br></div><div><b>References=
 to objects</b> can be and are treated exactly like the referenced object i=
tself.</div><div>Note that this only concerns the <b>run-time</b>.</div><di=
v>On the other hand a <i>reference type</i> is not a class, it is ... a ref=
erence.</div><div><br></div><div>IMHO it is very consequent, that e.g. <spa=
n style=3D"background-color: rgb(245, 245, 245); color: rgb(51, 51, 51); fo=
nt-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; fon=
t-size: 13.3333px; white-space: pre;">T::r</span>=C2=A0is not resolvable fo=
r=C2=A0<span style=3D"background-color: rgb(245, 245, 245); color: rgb(51, =
51, 51); font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, mon=
ospace; font-size: 13.3333px; white-space: pre;">T</span>=C2=A0being a refe=
rence type,</div><div>because its not a class, struct or union type.</div><=
div><br></div><div>Cheers</div><div>Jakob</div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/23d75c32-3724-49fa-961a-cb4a2c7259b7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/23d75c32-3724-49fa-961a-cb4a2c7259b7=
%40isocpp.org</a>.<br />

------=_Part_1994_1935460801.1492675045360--

------=_Part_1993_1787644953.1492675045360--

.


Author: Dan Raviv <dan.raviv@gmail.com>
Date: Thu, 27 Apr 2017 13:23:22 -0700 (PDT)
Raw View
------=_Part_15_269917534.1493324602096
Content-Type: multipart/alternative;
 boundary="----=_Part_16_1675324590.1493324602096"

------=_Part_16_1675324590.1493324602096
Content-Type: text/plain; charset=UTF-8

+1 for this non-breaking feature which has a similar precedent
(cv-qualifiers listed in Richard's answer), and which would simplify
writing (and *reading*) generic code.

Cheers,
Dan

On Tuesday, March 14, 2017 at 7:03:06 PM UTC+1, Walter Heisenbug wrote:
>
> Currently to access a member type from a reference type means you have to
> do all the dancing with removing the reference.
>
> template<typename T>
> void f(T&& x)
> {
>     typedef typename std::remove_reference_t<T>::member_type mem;
>     mem y;
>     use(std::forward<T>(x), y);
> }
>
> This could be simplified, if we allow to access the member types of a type
> from a reference types:
>
> template<typename T>
> void f(T&& x)
> {
>     typedef typename T::member_type mem;
>     mem y;
>     use(std::forward<T>(x), y);
> }
>
> I'm not aware of any potential problems, since the reference types don't
> have any member types, so there's no ambiguity with the existing code.

--
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/14a2d202-4b34-4e5b-b4f7-bfcfe090408f%40isocpp.org.

------=_Part_16_1675324590.1493324602096
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">+1 for this non-breaking feature which has a similar prece=
dent (cv-qualifiers listed in Richard&#39;s answer), and which would simpli=
fy writing (and *reading*) generic code.<br><br>Cheers,<div>Dan</div><div><=
br>On Tuesday, March 14, 2017 at 7:03:06 PM UTC+1, Walter Heisenbug wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;">Currently to access a member ty=
pe from a reference type means you have to do all the dancing with removing=
 the reference.=20
<br>
<br>template&lt;typename T&gt;
<br>void f(T&amp;&amp; x)
<br>{
<br>=C2=A0=C2=A0=C2=A0 typedef typename std::remove_reference_t&lt;T&gt;::<=
wbr>member_type mem;
<br>=C2=A0=C2=A0=C2=A0 mem y;
<br>=C2=A0=C2=A0=C2=A0 use(std::forward&lt;T&gt;(x), y);
<br>}
<br>
<br>This could be simplified, if we allow to access the member types of a t=
ype from a reference types:
<br>
<br>template&lt;typename T&gt;
<br>void f(T&amp;&amp; x)
<br>{
<br>=C2=A0 =C2=A0 typedef typename T::member_type mem;
<br>=C2=A0 =C2=A0 mem y;
<br>=C2=A0 =C2=A0 use(std::forward&lt;T&gt;(x), y);
<br>}
<br>
<br>I&#39;m not aware of any potential problems, since the reference types =
don&#39;t have any member types, so there&#39;s no ambiguity with the exist=
ing code. </blockquote></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/14a2d202-4b34-4e5b-b4f7-bfcfe090408f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/14a2d202-4b34-4e5b-b4f7-bfcfe090408f=
%40isocpp.org</a>.<br />

------=_Part_16_1675324590.1493324602096--

------=_Part_15_269917534.1493324602096--

.