Topic: Array as template parameter
Author: gufideg@gmail.com
Date: Thu, 15 Dec 2016 13:53:00 -0800 (PST)
Raw View
------=_Part_1438_533388016.1481838780309
Content-Type: multipart/alternative;
boundary="----=_Part_1439_422791372.1481838780309"
------=_Part_1439_422791372.1481838780309
Content-Type: text/plain; charset=UTF-8
Hi everyone,
I was thinking about a solution for the string literal as template
parameter. That solution would be to allow arrays to be a template parameter
template<char[] someString>
void someFunction() {}
And it would be called like this:
someFunction<"a char array!">();
This could also work for integers:
template<int[] someInts>
void someFunction();
someFunction<{1, 2, 3, 4, 9}>();
That way, you could effectively have multiple array parameter:
template<char[], int[], int[]>
void test();
test<"chars", {1, 4, 5}, {3, 2, 1}>();
The advantage of this solution would be performance. Some argue that
manipulating packs around for strings are inefficient way to do the work,
and hard for the compiler to do. Arrays as template parameters would still
be one template parameter, but holding many values.
Also, it gives us a way to pass around multiple groups of values around,
and obviously, pass strings as template parameter.
The disadvantages of this solution would be that one cannot unpack an array
template parameter without index_sequence, and may cause some ambiguities
with current template parameter types (pointer to extern object as template
parameter)
Thanks for your time!
--
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/1cfafdfa-d91d-4579-87af-bf889e3cbb06%40isocpp.org.
------=_Part_1439_422791372.1481838780309
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi everyone,<div><br></div><div>I was thinking about a sol=
ution for the string literal as template parameter. That solution would be =
to allow arrays to be a template parameter</div><div><br></div><div><div cl=
ass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-c=
olor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap=
: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><f=
ont color=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">template</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">cha=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[]</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> someString</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">void</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> someFunction</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></font></div></code></div><br>And it wo=
uld be called like this:</div><div><br></div><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;"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #000;" class=3D"styled-by-prettify">someFunction</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #0=
80;" class=3D"styled-by-prettify">"a char array!"</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">>();</span></div></code=
></div><br></div><div><br></div><div>This could also work for integers:</di=
v><div><br></div><div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">template</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[]</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> someInts</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">></span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> someFunction</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br><br>someFunction</span><span styl=
e=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;" 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"> <=
/span><span style=3D"color: #066;" class=3D"styled-by-prettify">3</span><sp=
an 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">4</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">9</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">}>();</span></div></code></div><div><br></div><div><br></div><div>That=
way, you could effectively have multiple array parameter:</div><div><br></=
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"><div class=3D"subpret=
typrint"><span style=3D"color: #008;" class=3D"styled-by-prettify">template=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">char</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">int</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">[],</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">[]></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">vo=
id</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> test</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br>test</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><sp=
an style=3D"color: #080;" class=3D"styled-by-prettify">"chars"</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span 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;" 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">4</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #066;" class=3D"styled-by-prettify">5</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: #660;"=
class=3D"styled-by-prettify">{</span><span style=3D"color: #066;" class=3D=
"styled-by-prettify">3</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">2</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}>();</span></div></code></div><div></d=
iv><div><br></div><div>The advantage of this solution would be performance.=
Some argue that manipulating packs around for strings are inefficient way =
to do the work, and hard for the compiler to do. Arrays as template paramet=
ers would still be one template parameter, but holding many values.</div><d=
iv><br></div><div>Also, it gives us a way to pass around multiple groups of=
values around, and obviously, pass strings as template parameter.</div><di=
v><br></div><div>The disadvantages of this solution would be that one canno=
t unpack an array template parameter without index_sequence, and may cause =
some ambiguities with current template parameter types (pointer to extern o=
bject as template parameter)</div><div><div><br></div></div><div>Thanks for=
your time!</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/1cfafdfa-d91d-4579-87af-bf889e3cbb06%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1cfafdfa-d91d-4579-87af-bf889e3cbb06=
%40isocpp.org</a>.<br />
------=_Part_1439_422791372.1481838780309--
------=_Part_1438_533388016.1481838780309--
.
Author: Daniel Boles <db0451@gmail.com>
Date: Thu, 15 Dec 2016 21:59:56 +0000
Raw View
On Thu, 2016-12-15 at 13:53 -0800, gufideg@gmail.com wrote:
> Hi everyone,
>=20
> I was thinking about a solution for the string literal as template
> parameter. That solution would be to allow arrays to be a template
> parameter
>=20
> template<char[] someString>
> void someFunction() {}
>=20
> And it would be called like this:
>=20
> someFunction<"a char array!">();
But "a char array!" is not a char array. It's a null-terminated
string.=C2=A0
Do you propose to make this syntax behave differently in different
contexts? I wouldn't advise it.
--=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/1481839196.32077.0.camel%40gmail.com.
.
Author: =?UTF-8?Q?Micha=C5=82_Dominiak?= <griwes@griwes.info>
Date: Thu, 15 Dec 2016 22:02:47 +0000
Raw View
--001a113cf7bec126a60543b99de4
Content-Type: text/plain; charset=UTF-8
Daniel: http://coliru.stacked-crooked.com/a/fbfa5ea41c4c3d8f
On Thu, Dec 15, 2016 at 11:00 PM Daniel Boles <db0451@gmail.com> wrote:
> On Thu, 2016-12-15 at 13:53 -0800, gufideg@gmail.com wrote:
> > Hi everyone,
> >
> > I was thinking about a solution for the string literal as template
> > parameter. That solution would be to allow arrays to be a template
> > parameter
> >
> > template<char[] someString>
> > void someFunction() {}
> >
> > And it would be called like this:
> >
> > someFunction<"a char array!">();
>
> But "a char array!" is not a char array. It's a null-terminated
> string.
>
> Do you propose to make this syntax behave differently in different
> contexts? I wouldn't advise it.
>
> --
> 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/1481839196.32077.0.camel%40gmail.com
> .
>
--
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/CAPCFJdRK%3DNOwhCoLZcaFy6StfZP4V4MpA54%3Dt4eyB9crnVMpyQ%40mail.gmail.com.
--001a113cf7bec126a60543b99de4
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Daniel:=C2=A0<a href=3D"http://coliru.stacked-crooked.com/=
a/fbfa5ea41c4c3d8f">http://coliru.stacked-crooked.com/a/fbfa5ea41c4c3d8f</a=
><br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Thu, Dec 15, =
2016 at 11:00 PM Daniel Boles <<a href=3D"mailto:db0451@gmail.com">db045=
1@gmail.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, =
2016-12-15 at 13:53 -0800, <a href=3D"mailto:gufideg@gmail.com" class=3D"gm=
ail_msg" target=3D"_blank">gufideg@gmail.com</a> wrote:<br class=3D"gmail_m=
sg">
> Hi everyone,<br class=3D"gmail_msg">
><br class=3D"gmail_msg">
> I was thinking about a solution for the string literal as template<br =
class=3D"gmail_msg">
> parameter. That solution would be to allow arrays to be a template<br =
class=3D"gmail_msg">
> parameter<br class=3D"gmail_msg">
><br class=3D"gmail_msg">
> template<char[] someString><br class=3D"gmail_msg">
> void someFunction() {}<br class=3D"gmail_msg">
><br class=3D"gmail_msg">
> And it would be called like this:<br class=3D"gmail_msg">
><br class=3D"gmail_msg">
> someFunction<"a char array!">();<br class=3D"gmail_msg=
">
<br class=3D"gmail_msg">
But "a char array!" is not a char array. It's a null-terminat=
ed<br class=3D"gmail_msg">
string.=C2=A0<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
Do you propose to make this syntax behave differently in different<br class=
=3D"gmail_msg">
contexts? I wouldn't advise it.<br class=3D"gmail_msg">
<br class=3D"gmail_msg">
--<br class=3D"gmail_msg">
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br class=3D"gmail_msg=
">
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" class=3D"=
gmail_msg" target=3D"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br c=
lass=3D"gmail_msg">
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" class=3D"gmail_msg" target=3D"_blank">std-proposals@isocpp.org</a>.<b=
r class=3D"gmail_msg">
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1481839196.32077.0.camel%40gmail.com"=
rel=3D"noreferrer" class=3D"gmail_msg" target=3D"_blank">https://groups.go=
ogle.com/a/isocpp.org/d/msgid/std-proposals/1481839196.32077.0.camel%40gmai=
l.com</a>.<br class=3D"gmail_msg">
</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/CAPCFJdRK%3DNOwhCoLZcaFy6StfZP4V4MpA5=
4%3Dt4eyB9crnVMpyQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAPCFJdRK%3DN=
OwhCoLZcaFy6StfZP4V4MpA54%3Dt4eyB9crnVMpyQ%40mail.gmail.com</a>.<br />
--001a113cf7bec126a60543b99de4--
.
Author: Daniel Boles <db0451@gmail.com>
Date: Thu, 15 Dec 2016 22:03:09 +0000
Raw View
I keep forgetting how eagerly C++ converts between arrays and pointers,
so I guess a char* _almost_ is a char[] in this context like many
others.
So I guess my question boils down to whether you want the same kind of
implicit conversion between arrays and pointers that happens elsewhere,
and if so, how the length information would be conveyed, unpacked, etc.
I see a hint of that in your post, but a demonstration would be great.
--
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/1481839389.32077.2.camel%40gmail.com.
.
Author: "T. C." <rs2740@gmail.com>
Date: Thu, 15 Dec 2016 14:17:19 -0800 (PST)
Raw View
------=_Part_310_1256700023.1481840239559
Content-Type: multipart/alternative;
boundary="----=_Part_311_285341816.1481840239559"
------=_Part_311_285341816.1481840239559
Content-Type: text/plain; charset=UTF-8
On Thursday, December 15, 2016 at 4:53:00 PM UTC-5, guf...@gmail.com wrote:
>
> Hi everyone,
>
> I was thinking about a solution for the string literal as template
> parameter. That solution would be to allow arrays to be a template parameter
>
> template<char[] someString>
> void someFunction() {}
>
> And it would be called like this:
>
> someFunction<"a char array!">();
>
>
> template<char s[]> void f(); is already valid today; the type of s is
adjusted to char*, just like function parameters.
template<char[] s> void f(); isn't valid but that declaration syntax isn't
seen anywhere else in C++.
Besides, what would template<char[]> void f(); mean?
--
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/5ff90f5e-6765-4706-838e-676132b419ce%40isocpp.org.
------=_Part_311_285341816.1481840239559
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, December 15, 2016 at 4:53:00 PM UTC-5=
, guf...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
dir=3D"ltr">Hi everyone,<div><br></div><div>I was thinking about a solution=
for the string literal as template parameter. That solution would be to al=
low arrays to be a template parameter</div><div><br></div><div><div 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><div><font color=
=3D"#660066"><span style=3D"color:#008">template</span><span style=3D"color=
:#660"><</span><span style=3D"color:#008">char</span><span style=3D"colo=
r:#660">[]</span><span style=3D"color:#000"> someString</span><span style=
=3D"color:#660">></span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#008">void</span><span style=3D"color:#000"> someFunction</span>=
<span style=3D"color:#660">()</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">{}</span></font></div></code></div><br>And it would =
be called like this:</div><div><br></div><div><div style=3D"background-colo=
r:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-=
width:1px;word-wrap:break-word"><code><div><span style=3D"color:#000">someF=
unction</span><span style=3D"color:#660"><</span><span style=3D"color:#0=
80">"a char array!"</span><span style=3D"color:#660">>();</spa=
n></div></code></div><br></div><div><br></div></div></blockquote><div>templ=
ate<char s[]> void f(); is already valid today; the type of s is adju=
sted to char*, just like function parameters.</div><div><br></div><div>temp=
late<char[] s> void f(); isn't valid but that declaration syntax =
isn't seen anywhere else in C++.</div><div><br></div><div>Besides, what=
would template<char[]> void f(); mean?</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/5ff90f5e-6765-4706-838e-676132b419ce%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5ff90f5e-6765-4706-838e-676132b419ce=
%40isocpp.org</a>.<br />
------=_Part_311_285341816.1481840239559--
------=_Part_310_1256700023.1481840239559--
.
Author: gufideg@gmail.com
Date: Thu, 15 Dec 2016 14:20:18 -0800 (PST)
Raw View
------=_Part_1303_1123134200.1481840418976
Content-Type: multipart/alternative;
boundary="----=_Part_1304_1390381424.1481840418977"
------=_Part_1304_1390381424.1481840418977
Content-Type: text/plain; charset=UTF-8
It would be unpacked a bit like how you would unpack a std:array or a
std::tuple
template<char[], typename>
struct SomeStructHelper;
template<char myArray[], std::size_t... S>
struct SomeStructHelper<myArray, std::index_sequence<S...>> {
// One can unpack like this: myArray[S]...
};
template<char myArray[]> // Replace LENGTH with the method one should use
to extract array lenght.
struct SomeStruct : SomeStructHelper<myArray, std::make_index_sequence<
LENGTH(myArray)>> {};
For length information, you could always use sizeof(myArray) /
sizeof(myArray[0]), but that would be ugly. I feel making a special case
for sizeof...() would be possible, but it's not a pack. I think a constexpr
function that returns the lenght would be better.
It comes to my mind: maybe we could also allow fixed length array:
// possible to set a fixed length for the array
template<char myArray[6]>
struct SomeStruct;
On Thursday, 15 December 2016 17:03:12 UTC-5, D. B. wrote:
>
> I keep forgetting how eagerly C++ converts between arrays and pointers,
> so I guess a char* _almost_ is a char[] in this context like many
> others.
>
> So I guess my question boils down to whether you want the same kind of
> implicit conversion between arrays and pointers that happens elsewhere,
> and if so, how the length information would be conveyed, unpacked, etc.
> I see a hint of that in your post, but a demonstration would be great.
>
--
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/c53f0d01-d511-4c99-8f83-e1755756f3f7%40isocpp.org.
------=_Part_1304_1390381424.1481840418977
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">It would be unpacked a bit like how you would unpack a std=
:array or a std::tuple<div><br></div><div><font color=3D"#666600"><div clas=
s=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-col=
or: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: =
break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"co=
lor: #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">typename</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">S=
omeStructHelper</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
<br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">templa=
te</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">char</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> myArray</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"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">size_t</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">...</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> S</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">SomeStruc=
tHelper</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">myArray</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</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">index_sequence</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">S</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-b=
y-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">// One can unpack like this: myArray[S]...</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"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">template</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">char</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> myArray</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">[]></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
</span><span style=3D"color: rgb(34, 34, 34); background-color: rgb(255, 2=
55, 255);"><font face=3D"courier new, monospace"><span style=3D"color: #800=
;" class=3D"styled-by-prettify">Replace LENGTH with the method one should u=
se to extract array lenght.</span></font><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">SomeStruct</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">SomeStructHelpe=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">myArray</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">make_index_sequence</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify">LENGTH</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">myArray</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></div></code></div><div style=3D"font-family: monospac=
e;"><br></div><div style=3D"font-family: monospace;"><br></div></font></div=
><div>For length information, you could always use sizeof(myArray) / sizeof=
(myArray[0]), but that would be ugly. I feel making a special case for size=
of...() would be possible, but it's not a pack. I think a constexpr fun=
ction that returns the lenght would be better.</div><div><br></div><div>It =
comes to my mind: maybe we could also=C2=A0allow fixed length array:</div><=
div><br></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"><div class=
=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// possible to set a fixed length for the array</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">template</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">char</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> myArray</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">[</span><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">6</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">struct</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">SomeStruct</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">;</span></div></code></d=
iv><div><div style=3D"color: rgb(102, 102, 0); font-family: monospace;"><br=
></div></div><div><br>On Thursday, 15 December 2016 17:03:12 UTC-5, D. B. =
wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8=
ex;border-left: 1px #ccc solid;padding-left: 1ex;">I keep forgetting how ea=
gerly C++ converts between arrays and pointers,
<br>so I guess a char* _almost_ is a char[] in this context like many
<br>others.
<br>
<br>So I guess my question boils down to whether you want the same kind of
<br>implicit conversion between arrays and pointers that happens elsewhere,
<br>and if so, how the length information would be conveyed, unpacked, etc.
<br>I see a hint of that in your post, but a demonstration would be great.
<br></blockquote></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/c53f0d01-d511-4c99-8f83-e1755756f3f7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c53f0d01-d511-4c99-8f83-e1755756f3f7=
%40isocpp.org</a>.<br />
------=_Part_1304_1390381424.1481840418977--
------=_Part_1303_1123134200.1481840418976--
.
Author: Daniel Boles <db0451@gmail.com>
Date: Thu, 15 Dec 2016 22:24:08 +0000
Raw View
On Thu, 2016-12-15 at 14:20 -0800, gufideg@gmail.com wrote:
> For length information, you could always use sizeof(myArray) /
> sizeof(myArray[0]), but that would be ugly. I feel making a special
> case for sizeof...() would be possible, but it's not a pack. I think
> a constexpr function that returns the lenght would be better.
Good news: In C++17, std::size is specialised for raw arrays, so it
will be able to do this for you.
--
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/1481840648.32077.4.camel%40gmail.com.
.
Author: gufideg@gmail.com
Date: Thu, 15 Dec 2016 14:53:05 -0800 (PST)
Raw View
------=_Part_1288_1707477997.1481842385233
Content-Type: text/plain; charset=UTF-8
It would mean an array of a size to be deduced. Here's an example of what I meant:
template<int[] arr> void foo();
foo<{2, 6, 7, 8}>(); // arr is char[4]
Sorry for the formatting, I'm on mobile right now.
--
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/abcb0ef0-4f0f-407d-8faf-f536ec6e1f33%40isocpp.org.
------=_Part_1288_1707477997.1481842385233--
.