Topic: Syntactic sugar for std::array?
Author: Peet <peetnick2@gmail.com>
Date: Sat, 3 Dec 2016 12:55:07 -0800 (PST)
Raw View
------=_Part_1149_1594799526.1480798507944
Content-Type: multipart/alternative;
boundary="----=_Part_1150_374039756.1480798507944"
------=_Part_1150_374039756.1480798507944
Content-Type: text/plain; charset=UTF-8
Hey,
Perhaps I am not the only one who sometimes is going to write long
std::array types, I mean very long types, eg.:
std::array<std::unordered_map<uint32_t, std::vector<std::array<uint16_t, 8>>>, 8> complexArray{};
I had this thought, if it would have been easier to read if the type was
written differently:
[std::unordered_map<uint32_t, std::vector<[uint16_t, 8]>>, 8] complexArray{};
The syntax [ type, size ] is basically syntactic sugar for std::array<type,
size>.
What do you think?
~Nick
--
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/69fe6b40-addb-47f8-82d2-7f927aed537b%40isocpp.org.
------=_Part_1150_374039756.1480798507944
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hey,<div><br></div><div>Perhaps I am not the only one who =
sometimes is going to write long std::array types, I mean very long types, =
eg.:</div><div><br></div><div><pre style=3D"color: rgb(0, 0, 32); backgroun=
d: rgb(246, 248, 255);"><span style=3D"color: rgb(0, 102, 238);">std</span>=
<span style=3D"color: rgb(64, 96, 128);">::</span><span style=3D"color: rgb=
(0, 48, 96);">array</span><span style=3D"color: rgb(48, 128, 128);"><</s=
pan><span style=3D"color: rgb(0, 102, 238);">std</span><span style=3D"color=
: rgb(64, 96, 128);">::</span><span style=3D"color: rgb(0, 48, 96);">unorde=
red_map</span><span style=3D"color: rgb(48, 128, 128);"><</span>uint32_t=
<span style=3D"color: rgb(48, 128, 128);">,</span> <span style=3D"color: rg=
b(0, 102, 238);">std</span><span style=3D"color: rgb(64, 96, 128);">::</spa=
n><span style=3D"color: rgb(0, 48, 96);">vector</span><span style=3D"color:=
rgb(48, 128, 128);"><</span><span style=3D"color: rgb(0, 102, 238);">st=
d</span><span style=3D"color: rgb(64, 96, 128);">::</span><span style=3D"co=
lor: rgb(0, 48, 96);">array</span><span style=3D"color: rgb(48, 128, 128);"=
><</span>uint16_t<span style=3D"color: rgb(48, 128, 128);">,</span> <spa=
n style=3D"color: rgb(0, 140, 0);">8</span><span style=3D"color: rgb(48, 12=
8, 128);">></span><span style=3D"color: rgb(48, 128, 128);">></span><=
span style=3D"color: rgb(48, 128, 128);">></span><span style=3D"color: r=
gb(48, 128, 128);">,</span> <span style=3D"color: rgb(0, 140, 0);">8</span>=
<span style=3D"color: rgb(48, 128, 128);">></span> complexArray<span sty=
le=3D"color: rgb(64, 96, 128);">{</span><span style=3D"color: rgb(64, 96, 1=
28);">}</span><span style=3D"color: rgb(64, 96, 128);">;</span></pre></div>=
<div><div><br></div><div>I had this thought, if it would have been easier t=
o read if the type was written differently:</div><div><br></div><div><pre s=
tyle=3D"color: rgb(0, 0, 32); background: rgb(246, 248, 255);"><span style=
=3D"color: rgb(48, 128, 128);">[</span><span style=3D"color: rgb(0, 102, 23=
8);">std</span><span style=3D"color: rgb(64, 96, 128);">::</span><span styl=
e=3D"color: rgb(0, 48, 96);">unordered_map</span><span style=3D"color: rgb(=
48, 128, 128);"><</span>uint32_t<span style=3D"color: rgb(48, 128, 128);=
">,</span> <span style=3D"color: rgb(0, 102, 238);">std</span><span style=
=3D"color: rgb(64, 96, 128);">::</span><span style=3D"color: rgb(0, 48, 96)=
;">vector</span><span style=3D"color: rgb(48, 128, 128);"><</span><span =
style=3D"color: rgb(48, 128, 128);">[</span>uint16_t<span style=3D"color: r=
gb(48, 128, 128);">,</span> <span style=3D"color: rgb(0, 140, 0);">8</span>=
<span style=3D"color: rgb(48, 128, 128);">]</span><span style=3D"color: rgb=
(48, 128, 128);">></span><span style=3D"color: rgb(48, 128, 128);">><=
/span><span style=3D"color: rgb(48, 128, 128);">,</span> <span style=3D"col=
or: rgb(0, 140, 0);">8</span><span style=3D"color: rgb(48, 128, 128);">]</s=
pan> complexArray<span style=3D"color: rgb(64, 96, 128);">{</span><span sty=
le=3D"color: rgb(64, 96, 128);">}</span><span style=3D"color: rgb(64, 96, 1=
28);">;</span></pre></div><div><br></div><div>The syntax=C2=A0<span style=
=3D"color: rgb(48, 128, 128);">[</span><span style=3D"background-color: rgb=
(246, 248, 255); color: rgb(0, 0, 32);"> type</span><span style=3D"color: r=
gb(48, 128, 128);">,</span><span style=3D"background-color: rgb(246, 248, 2=
55); color: rgb(0, 0, 32);"> size </span><span style=3D"color: rgb(48, 128,=
128);">]=C2=A0</span>is basically syntactic sugar for=C2=A0<span style=3D"=
color: rgb(0, 102, 238);">std</span><span style=3D"color: rgb(64, 96, 128);=
">::</span><span style=3D"color: rgb(0, 48, 96);">array</span><span style=
=3D"color: rgb(64, 96, 128);"><</span><span style=3D"background-color: r=
gb(246, 248, 255); color: rgb(0, 0, 32);">type</span><span style=3D"color: =
rgb(48, 128, 128);">,</span><span style=3D"background-color: rgb(246, 248, =
255); color: rgb(0, 0, 32);"> size</span><span style=3D"color: rgb(64, 96, =
128);">></span>.<br><br>What do you think?<br><br>~Nick</div></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/69fe6b40-addb-47f8-82d2-7f927aed537b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/69fe6b40-addb-47f8-82d2-7f927aed537b=
%40isocpp.org</a>.<br />
------=_Part_1150_374039756.1480798507944--
------=_Part_1149_1594799526.1480798507944--
.
Author: Daniel Boles <db0451@gmail.com>
Date: Sat, 03 Dec 2016 21:02:14 +0000
Raw View
As much as I hate typing, this seems like a 'slippery slope' thing to
me... why not hijack all kinds of other punctuations as shortcuts for
other types? but what if your commonly used types differ from other
people?
Plus, I feel like using square brackets is likely to make an even
tougher job for the people writing parsers nowadays, what with lambdas
and structured bindings (or whatever it's called now) floating around.
But YMMV
--
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/1480798934.14859.1.camel%40gmail.com.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 3 Dec 2016 13:09:49 -0800 (PST)
Raw View
------=_Part_1153_128043188.1480799389092
Content-Type: multipart/alternative;
boundary="----=_Part_1154_737199393.1480799389092"
------=_Part_1154_737199393.1480799389092
Content-Type: text/plain; charset=UTF-8
We already have a lot of uses for square-brackets as it is: array access,
lambdas, and structured binding (depending on how the committees decided).
We really don't need more.
Besides, the `std::array` part of that declaration seems to be the
*shortest* part. This wouldn't be a problem if you created a nice alias for
that map type.
--
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/19154102-dc47-4a68-8bd9-11eb2e9d00ea%40isocpp.org.
------=_Part_1154_737199393.1480799389092
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">We already have a lot of uses for square-brackets as it is=
: array access, lambdas, and structured binding (depending on how the commi=
ttees decided). We really don't need more.<br><br>Besides, the `std::ar=
ray` part of that declaration seems to be the <i>shortest</i> part. This wo=
uldn't be a problem if you created a nice alias for that map type.</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/19154102-dc47-4a68-8bd9-11eb2e9d00ea%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/19154102-dc47-4a68-8bd9-11eb2e9d00ea=
%40isocpp.org</a>.<br />
------=_Part_1154_737199393.1480799389092--
------=_Part_1153_128043188.1480799389092--
.
Author: Derek Ross <antiquarktv@gmail.com>
Date: Sat, 3 Dec 2016 15:47:31 -0800 (PST)
Raw View
------=_Part_646_1456629213.1480808851529
Content-Type: multipart/alternative;
boundary="----=_Part_647_349628514.1480808851530"
------=_Part_647_349628514.1480808851530
Content-Type: text/plain; charset=UTF-8
As Nick Bolas said, usually aliases are the way to simplify complicated
types. In this case you could do something like:
using arr_t = std::array<uint16_t, 8>;
using vecarr_t = std::vector<arr_t>;
using unomap_t = std::unordered_map<uint32_t, vecarr_t>;
std::array<unomap_t, 8> complexArray{};
On Saturday, December 3, 2016 at 2:55:08 PM UTC-6, Peet wrote:
>
> Hey,
>
> Perhaps I am not the only one who sometimes is going to write long
> std::array types, I mean very long types, eg.:
>
> std::array<std::unordered_map<uint32_t, std::vector<std::array<uint16_t, 8>>>, 8> complexArray{};
>
>
> I had this thought, if it would have been easier to read if the type was
> written differently:
>
> [std::unordered_map<uint32_t, std::vector<[uint16_t, 8]>>, 8] complexArray{};
>
>
> The syntax [ type, size ] is basically syntactic sugar for std::array<type
> , size>.
>
> What do you think?
>
> ~Nick
>
--
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/4cb99f53-4337-4c2b-87c8-fbdbf7bd30d3%40isocpp.org.
------=_Part_647_349628514.1480808851530
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">As Nick Bolas said, usually aliases are the way to simplif=
y complicated types. In this case you could do something like:<br><br><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-wr=
ap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 <br=
></span><span style=3D"color: #008;" class=3D"styled-by-prettify">using</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> arr_t </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">array</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">uint16_t</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">8</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">using</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> vecarr_t </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">vector</span><span style=3D"color: #=
080;" class=3D"styled-by-prettify"><arr_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><span style=3D"color: #008;" class=
=3D"styled-by-prettify">using</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> unomap_t </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">un=
ordered_map</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">uint3=
2_t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> vecarr_t</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">>;</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br>std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">array</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">unomap_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: #066;" class=3D"styled-by=
-prettify">8</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">></span><span style=3D"color: #000;" class=3D"styled-by-prettify"> com=
plexArray</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=
</span></div></code></div><br><br><br>On Saturday, December 3, 2016 at 2:55=
:08 PM UTC-6, Peet 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"ltr">Hey,<div><br></div><div>Perhaps I am not the only one who somet=
imes is going to write long std::array types, I mean very long types, eg.:<=
/div><div><br></div><div><pre style=3D"color:rgb(0,0,32);background:rgb(246=
,248,255)"><span style=3D"color:rgb(0,102,238)">std</span><span style=3D"co=
lor:rgb(64,96,128)">::</span><span style=3D"color:rgb(0,48,96)">array</span=
><span style=3D"color:rgb(48,128,128)"><</span><span style=3D"color:rgb(=
0,102,238)">std</span><span style=3D"color:rgb(64,96,128)">::</span><span s=
tyle=3D"color:rgb(0,48,96)">unordered_map</span><span style=3D"color:rgb(48=
,128,128)"><</span><wbr>uint32_t<span style=3D"color:rgb(48,128,128)">,<=
/span> <span style=3D"color:rgb(0,102,238)">std</span><span style=3D"color:=
rgb(64,96,128)">::</span><span style=3D"color:rgb(0,48,96)">vector</span><s=
pan style=3D"color:rgb(48,128,128)"><</span><span style=3D"color:rgb(0,1=
02,238)">std</span><span style=3D"color:rgb(64,96,128)">::</span><span styl=
e=3D"color:rgb(0,48,96)">array</span><span style=3D"color:rgb(48,128,128)">=
<</span>uint16_<wbr>t<span style=3D"color:rgb(48,128,128)">,</span> <spa=
n style=3D"color:rgb(0,140,0)">8</span><span style=3D"color:rgb(48,128,128)=
">></span><span style=3D"color:rgb(48,128,128)">></span><span style=
=3D"color:rgb(48,128,128)">></span><span style=3D"color:rgb(48,128,128)"=
>,</span> <span style=3D"color:rgb(0,140,0)">8</span><span style=3D"color:r=
gb(48,128,128)">></span> complexArray<span style=3D"color:rgb(64,96,128)=
">{</span><span style=3D"color:rgb(64,96,128)">}</span><span style=3D"color=
:rgb(64,96,128)">;</span></pre></div><div><div><br></div><div>I had this th=
ought, if it would have been easier to read if the type was written differe=
ntly:</div><div><br></div><div><pre style=3D"color:rgb(0,0,32);background:r=
gb(246,248,255)"><span style=3D"color:rgb(48,128,128)">[</span><span style=
=3D"color:rgb(0,102,238)">std</span><span style=3D"color:rgb(64,96,128)">::=
</span><span style=3D"color:rgb(0,48,96)">unordered_map</span><span style=
=3D"color:rgb(48,128,128)"><</span>uint32_t<span style=3D"color:rgb(48,1=
28,128)">,</span> <span style=3D"color:rgb(0,102,238)">std</span><span styl=
e=3D"color:rgb(64,96,128)">::</span><span style=3D"color:rgb(0,48,96)">vect=
or</span><span style=3D"color:rgb(48,128,128)"><</span><span style=3D"co=
lor:rgb(48,128,128)">[</span>uint16_t<span style=3D"color:rgb(48,128,128)">=
,</span> <span style=3D"color:rgb(0,140,0)">8</span><span style=3D"color:rg=
b(48,128,128)">]</span><span style=3D"color:rgb(48,128,128)">></span><sp=
an style=3D"color:rgb(48,128,128)">></span><span style=3D"color:rgb(48,1=
28,128)">,</span> <span style=3D"color:rgb(0,140,0)">8</span><span style=3D=
"color:rgb(48,128,128)">]</span> complexArray<span style=3D"color:rgb(64,96=
,128)">{</span><span style=3D"color:rgb(64,96,128)">}</span><span style=3D"=
color:rgb(64,96,128)">;</span></pre></div><div><br></div><div>The syntax=C2=
=A0<span style=3D"color:rgb(48,128,128)">[</span><span style=3D"background-=
color:rgb(246,248,255);color:rgb(0,0,32)"> type</span><span style=3D"color:=
rgb(48,128,128)">,</span><span style=3D"background-color:rgb(246,248,255);c=
olor:rgb(0,0,32)"> size </span><span style=3D"color:rgb(48,128,128)">]=C2=
=A0</span>is basically syntactic sugar for=C2=A0<span style=3D"color:rgb(0,=
102,238)">std</span><span style=3D"color:rgb(64,96,128)">::</span><span sty=
le=3D"color:rgb(0,48,96)">array</span><span style=3D"color:rgb(64,96,128)">=
<</span><span style=3D"background-color:rgb(246,248,255);color:rgb(0,0,3=
2)">type</span><span style=3D"color:rgb(48,128,128)">,</span><span style=3D=
"background-color:rgb(246,248,255);color:rgb(0,0,32)"> size</span><span sty=
le=3D"color:rgb(64,96,128)">></span>.<br><br>What do you think?<br><br>~=
Nick</div></div></div></blockquote></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/4cb99f53-4337-4c2b-87c8-fbdbf7bd30d3%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4cb99f53-4337-4c2b-87c8-fbdbf7bd30d3=
%40isocpp.org</a>.<br />
------=_Part_647_349628514.1480808851530--
------=_Part_646_1456629213.1480808851529--
.