Topic: Add type alias that mirrors given type
Author: Antonio Perez <antonio@perezexcelsior.com>
Date: Wed, 2 Aug 2017 12:27:51 -0700 (PDT)
Raw View
------=_Part_6308_1356206439.1501702071927
Content-Type: multipart/alternative;
boundary="----=_Part_6309_160872515.1501702071928"
------=_Part_6309_160872515.1501702071928
Content-Type: text/plain; charset="UTF-8"
I propose that a type alias which simply returns the given type be added to
the standard library for the purpose of working with types whose syntax is
problematic.
The definition could be as follows:
template<class T> using typemirror = T;
*What's the use for this?*As an example usage, here is a print function
that prints an array of things:
template<class T, size_t n> void print(std::typemirror<T[n]>& arr)
{
if constexpr(std::is_same<T, char>::value) { std::cout << arr; }
if constexpr(n == 0) { std::cout << "{}"; }
else {
std::cout << '{' << arr[0];
for(size_t i = 1; i < n; ++i) {
std::cout << ", " << arr[i];
}
std::cout << '}';
}
}
And here's the usage:
int main() {
int arr[] = {1, 2, 3};
print(arr);
std::cout << std::endl;
}
//Output:
//{1, 2, 3}
--
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/20f365ce-2a24-4576-894f-923e7b9cd76e%40isocpp.org.
------=_Part_6309_160872515.1501702071928
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I propose that a type alias which simply returns the given=
type be added to the standard library for the purpose of working with type=
s whose syntax is problematic.<br><br>The definition could be as follows:<b=
r><br><div style=3D"background-color: rgb(250, 250, 250); border-color: rgb=
(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: bre=
ak-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">te=
mplate</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</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">using</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> typemirror </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> T</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><b>What's the use for this=
?<br><br></b>As an example usage, here is a print function that prints an a=
rray of things:<br><br><div style=3D"background-color: rgb(250, 250, 250); =
border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; o=
verflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprint=
"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">template</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> size_t n</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">void</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">print</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
typemirror</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
<</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">n</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">]>&</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> arr</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" cl=
ass=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-b=
y-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">if</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">constexpr</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">is_same</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">char</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">>::</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">value</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 st=
yle=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"styled-by-prettify">cout </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> arr</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: #660;" class=3D"styled-by-pret=
tify">}</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-prett=
ify">if</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">n </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" clas=
s=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"> s=
td</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><spa=
n 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: #080;" 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: #660;" =
class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">else</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"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">cout </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify"><<</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-pr=
ettify">'{'</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
<<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a=
rr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span>=
<span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">];</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">for</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">size_t i </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" 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"style=
d-by-prettify"> i </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> n</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: #660;" class=3D"styled-by-prettify">++</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">i</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">)</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"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify"><<</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">", "</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"sty=
led-by-prettify"> arr</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">[</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">i</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 =C2=
=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">cout </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #080;" 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"><br>=C2=
=A0 =C2=A0 </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: #660;" class=3D"styled-by-prettify">}</span></div>=
</code></div><br><br>And here's the usage:<br><br><div style=3D"backgro=
und-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-sty=
le: solid; border-width: 1px; overflow-wrap: break-word;" class=3D"prettypr=
int"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> main</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> arr</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">[]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an 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=
: #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: #066;" class=3D"styled-by=
-prettify">2</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: #066;" class=3D"styled-by-prettify">3</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">print</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">arr</span><span 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 std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">cout </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">endl</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">//Output:</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">//{1, 2, 3}</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><b=
r><br></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/20f365ce-2a24-4576-894f-923e7b9cd76e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/20f365ce-2a24-4576-894f-923e7b9cd76e=
%40isocpp.org</a>.<br />
------=_Part_6309_160872515.1501702071928--
------=_Part_6308_1356206439.1501702071927--
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Thu, 3 Aug 2017 09:35:29 -0400
Raw View
On 2017-08-02 15:27, Antonio Perez wrote:
> I propose that a type alias which simply returns the given type be added to
> the standard library for the purpose of working with types whose syntax is
> problematic.
>
> *What's the use for this?*As an example usage, here is a print function
> that prints an array of things:
> > template<class T, size_t n> void print(std::typemirror<T[n]>& arr)
Um...
template <typename T, size_t N>
void print(T (&arr)[N])
....?
I don't see a motivating use case here...
--
Matthew
--
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/edbf0c37-4672-0c79-d95b-331b3812ba1c%40gmail.com.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 3 Aug 2017 06:54:29 -0700 (PDT)
Raw View
------=_Part_5451_1861794337.1501768469980
Content-Type: multipart/alternative;
boundary="----=_Part_5452_2039268355.1501768469980"
------=_Part_5452_2039268355.1501768469980
Content-Type: text/plain; charset="UTF-8"
On Thursday, August 3, 2017 at 9:35:36 AM UTC-4, Matthew Woehlke wrote:
>
> On 2017-08-02 15:27, Antonio Perez wrote:
> > I propose that a type alias which simply returns the given type be added
> to
> > the standard library for the purpose of working with types whose syntax
> is
> > problematic.
> >
> > *What's the use for this?*As an example usage, here is a print function
> > that prints an array of things:
> > > template<class T, size_t n> void print(std::typemirror<T[n]>& arr)
>
> Um...
>
> template <typename T, size_t N>
> void print(T (&arr)[N])
>
> ...?
>
> I don't see a motivating use case here...
>
I think the motivation here is that that syntax looks *terrible* and quite
a few people have no idea how to type that. The type of the object `arr`
references is `T[N]`, so why isn't it on the left where types go? Every
time I have to write something like that, I have to look up how to do it
properly.
Granted, since I got hold of gsl::span, I haven't had need to take such a
horrible type anymore.
--
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/03d0948e-506b-4e0b-b5e0-b255d3698cd5%40isocpp.org.
------=_Part_5452_2039268355.1501768469980
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, August 3, 2017 at 9:35:36 AM UTC-4, Matthew W=
oehlke wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2017-08-02 15:=
27, Antonio Perez wrote:
<br>> I propose that a type alias which simply returns the given type be=
added to=20
<br>> the standard library for the purpose of working with types whose s=
yntax is=20
<br>> problematic.
<br>>=20
<br>> *What's the use for this?*As an example usage, here is a print=
function=20
<br>> that prints an array of things:
<br>> > template<class T, size_t n> void print(std::typemirror&=
lt;T[n]>& arr)
<br>
<br>Um...
<br>
<br>=C2=A0 template <typename T, size_t N>
<br>=C2=A0 void print(T (&arr)[N])
<br>
<br>...?
<br>
<br>I don't see a motivating use case here...<br></blockquote><div><br>=
I think the motivation here is that that syntax looks <i>terrible</i> and q=
uite a few people have no idea how to type that. The type of the object `ar=
r` references is `T[N]`, so why isn't it on the left where types go? Ev=
ery time I have to write something like that, I have to look up how to do i=
t properly.<br><br>Granted, since I got hold of gsl::span, I haven't ha=
d need to take such a horrible type anymore.<br></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/03d0948e-506b-4e0b-b5e0-b255d3698cd5%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/03d0948e-506b-4e0b-b5e0-b255d3698cd5=
%40isocpp.org</a>.<br />
------=_Part_5452_2039268355.1501768469980--
------=_Part_5451_1861794337.1501768469980--
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Thu, 3 Aug 2017 10:38:34 -0400
Raw View
On 2017-08-03 09:54, Nicol Bolas wrote:
> On Thursday, August 3, 2017 at 9:35:36 AM UTC-4, Matthew Woehlke wrote:
>> On 2017-08-02 15:27, Antonio Perez wrote:
>>> I propose that a type alias which simply returns the given type
>>> be added to the standard library for the purpose of working with
>>> types whose syntax is problematic.>>>
>>> *What's the use for this?*As an example usage, here is a print function
>>> that prints an array of things:
>>>
>>> template<class T, size_t n> void print(std::typemirror<T[n]>& arr)
>>
>> Um...
>>
>> template <typename T, size_t N>
>> void print(T (&arr)[N])
>>
>> ...?
>>
>> I don't see a motivating use case here...
>
> I think the motivation here is that that syntax looks *terrible* and quite
> a few people have no idea how to type that.
Yes, it's esoteric, but if this is the *only* motivation for the
feature, IMHO it isn't worth a new library feature.
(It's actually not *that* weird, either... function pointers aren't much
different...)
--
Matthew
--
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/7ba631a5-c4c5-cd5b-8e80-c583420cfca5%40gmail.com.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Aug 2017 18:10:09 +0300
Raw View
On 3 August 2017 at 17:38, Matthew Woehlke <mwoehlke.floss@gmail.com> wrote:
>>>> template<class T, size_t n> void print(std::typemirror<T[n]>& arr)
>>>
>>> Um...
>>>
>>> template <typename T, size_t N>
>>> void print(T (&arr)[N])
>>>
>>> ...?
>>>
>>> I don't see a motivating use case here...
>>
>> I think the motivation here is that that syntax looks *terrible* and quite
>> a few people have no idea how to type that.
>
> Yes, it's esoteric, but if this is the *only* motivation for the
> feature, IMHO it isn't worth a new library feature.
>
> (It's actually not *that* weird, either... function pointers aren't much
> different...)
Users of std::array have no such problems. I would recommend against
getting any hopes
up for improving raw arrays significantly in this area or any other
area, when a far superior
facility has been part of the standard for 6 years and ships in every
implementation you could
hope to adopt a language improvement.
--
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/CAFk2RUb3t%2B8HOWGpCtMw%2Bj7LZC-f0WLQ7LMX9Lz6d%3DkZCQB_yQ%40mail.gmail.com.
.
Author: Tom Honermann <tom@honermann.net>
Date: Thu, 3 Aug 2017 11:37:39 -0400
Raw View
This is a multi-part message in MIME format.
--------------1C58BEB03CAA1C0C5330EA98
Content-Type: text/plain; charset="UTF-8"; format=flowed
On 08/02/2017 03:27 PM, Antonio Perez wrote:
> I propose that a type alias which simply returns the given type be
> added to the standard library for the purpose of working with types
> whose syntax is problematic.
>
> The definition could be as follows:
>
> |
> template<classT>usingtypemirror =T;
> |
|This template is typically called identity (or identity_t) and is also
useful for disabling type deduction.
It might be worth trying to standardize it, but there is prior history
to be aware of:
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/vrrtKvA7cqo
Tom.|
--
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/58cf0b51-dc02-e7f8-43a0-8bcf1714e803%40honermann.net.
--------------1C58BEB03CAA1C0C5330EA98
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">On 08/02/2017 03:27 PM, Antonio Perez
wrote:<br>
</div>
<blockquote
cite=3D"mid:20f365ce-2a24-4576-894f-923e7b9cd76e@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">I propose that a type alias which simply returns
the given type be added to the standard library for the purpose
of working with types whose syntax is problematic.<br>
<br>
The definition could be as follows:<br>
<br>
<div style=3D"background-color: rgb(250, 250, 250); border-color:
rgb(187, 187, 187); border-style: solid; border-width: 1px;
overflow-wrap: break-word;" class=3D"prettyprint"><code
class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #008;" class=3D"styled-by-prettify">class</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T</spa=
n><span
style=3D"color: #660;" class=3D"styled-by-prettify">></s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">using</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
typemirror </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">=3D</span><span style=3D"color=
:
#000;" class=3D"styled-by-prettify"> T</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>
</div>
</blockquote>
<code>This template is typically called identity (or identity_t) and
is also useful for disabling type deduction.<br>
<br>
It might be worth trying to standardize it, but there is prior
history to be aware of:<br>
<br>
<a class=3D"moz-txt-link-freetext" href=3D"https://groups.google.com/a/isoc=
pp.org/forum/#!topic/std-proposals/vrrtKvA7cqo">https://groups.google.com/a=
/isocpp.org/forum/#!topic/std-proposals/vrrtKvA7cqo</a><br>
<br>
Tom.</code>
</body>
</html>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/58cf0b51-dc02-e7f8-43a0-8bcf1714e803%=
40honermann.net?utm_medium=3Demail&utm_source=3Dfooter">https://groups.goog=
le.com/a/isocpp.org/d/msgid/std-proposals/58cf0b51-dc02-e7f8-43a0-8bcf1714e=
803%40honermann.net</a>.<br />
--------------1C58BEB03CAA1C0C5330EA98--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 3 Aug 2017 18:59:17 +0300
Raw View
On 3 August 2017 at 18:37, Tom Honermann <tom@honermann.net> wrote:
> On 08/02/2017 03:27 PM, Antonio Perez wrote:
>
> I propose that a type alias which simply returns the given type be added to
> the standard library for the purpose of working with types whose syntax is
> problematic.
>
> The definition could be as follows:
>
> template<class T> using typemirror = T;
>
> This template is typically called identity (or identity_t) and is also
> useful for disabling type deduction.
>
> It might be worth trying to standardize it, but there is prior history to be
> aware of:
>
> https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/vrrtKvA7cqo
Ah, we have found (or rediscovered) a case where common_type_t<T>
doesn't do the same thing
as a real identity trait would.
--
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/CAFk2RUZ7N2TeoR_tsffEc%2Bchpn8zut48xo1YowtZbo5tOX1fAA%40mail.gmail.com.
.
Author: "T. C." <rs2740@gmail.com>
Date: Thu, 3 Aug 2017 11:08:58 -0700 (PDT)
Raw View
------=_Part_10_2033394916.1501783738828
Content-Type: multipart/alternative;
boundary="----=_Part_11_1690830438.1501783738829"
------=_Part_11_1690830438.1501783738829
Content-Type: text/plain; charset="UTF-8"
On Thursday, August 3, 2017 at 9:35:36 AM UTC-4, Matthew Woehlke wrote:
>
> On 2017-08-02 15:27, Antonio Perez wrote:
> > I propose that a type alias which simply returns the given type be added
> to
> > the standard library for the purpose of working with types whose syntax
> is
> > problematic.
> >
> > *What's the use for this?*As an example usage, here is a print function
> > that prints an array of things:
> > > template<class T, size_t n> void print(std::typemirror<T[n]>& arr)
>
> Um...
>
> template <typename T, size_t N>
> void print(T (&arr)[N])
>
> ...?
>
> I don't see a motivating use case here...
>
>
A marginally better use case is conversion functions. conversion-type-id
has a restricted grammar and doesn't accept array/function declarators, so
to write a conversion to, say, pointer to function, you have to resort to a
typedef.
struct X {
using fptr_t = int (*)();
operator fptr_t() { ... }
};
vs.
struct X {
operator identity_t<int(*)()> { ... }
};
and if you want to write a conversion function template, then you'd really
like `identity_t` to not disable deduction.
That said, I've only written a conversion to function pointer when trying
to explain how captureless lambdas work...
--
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/dc01ca40-ec6d-4839-ac8e-7e28cfb32ea2%40isocpp.org.
------=_Part_11_1690830438.1501783738829
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, August 3, 2017 at 9:35:36 AM UTC-4, M=
atthew Woehlke wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2017-0=
8-02 15:27, Antonio Perez wrote:
<br>> I propose that a type alias which simply returns the given type be=
added to=20
<br>> the standard library for the purpose of working with types whose s=
yntax is=20
<br>> problematic.
<br>>=20
<br>> *What's the use for this?*As an example usage, here is a print=
function=20
<br>> that prints an array of things:
<br>> > template<class T, size_t n> void print(std::typemirror&=
lt;T[n]>& arr)
<br>
<br>Um...
<br>
<br>=C2=A0 template <typename T, size_t N>
<br>=C2=A0 void print(T (&arr)[N])
<br>
<br>...?
<br>
<br>I don't see a motivating use case here...
<br>
<br></blockquote><div><br></div><div>A marginally better use case is conver=
sion functions. conversion-type-id has a restricted grammar and doesn't=
accept array/function declarators, so to write a conversion to, say, point=
er to function, you have to resort to a typedef.</div><div><br></div><div>s=
truct X {</div><div>=C2=A0 =C2=A0 using fptr_t =3D int (*)();</div><div>=C2=
=A0 =C2=A0 operator fptr_t() { ... }</div><div>};</div><div><br></div><div>=
vs.</div><div><br></div><div>struct X {</div><div>=C2=A0 =C2=A0 operator id=
entity_t<int(*)()> { ... }</div><div>};</div><div><br></div><div>and =
if you want to write a conversion function template, then you'd really =
like `identity_t` to not disable deduction.</div><div><br></div><div>That s=
aid, I've only written a conversion to function pointer when trying to =
explain how captureless lambdas work...</div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/dc01ca40-ec6d-4839-ac8e-7e28cfb32ea2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/dc01ca40-ec6d-4839-ac8e-7e28cfb32ea2=
%40isocpp.org</a>.<br />
------=_Part_11_1690830438.1501783738829--
------=_Part_10_2033394916.1501783738828--
.