Topic: Array initialization by an array?
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Thu, 20 Mar 2014 22:43:39 -0700 (PDT)
Raw View
------=_Part_675_16146603.1395380619611
Content-Type: text/plain; charset=UTF-8
Why can't an object of type array of N T be initialized by an expression of
type array of N T?
int x[3] = {1, 2, 3};
int y[3] = x; // ill-formed
I'm sure there must be a good reason for this being defined as ill-formed
in [dcl.init]/17b5...
Otherwise, if the destination type is an array, the program is
ill-formed
....but I don't quite see what it is.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_675_16146603.1395380619611
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Why can't an object of type array of N T be initialized by=
an expression of type array of N T?<div><br></div><div><div> =
int x[3] =3D {1, 2, 3};</div><div><br></div><div> int y[3] =3D=
x; // ill-formed</div></div><div><br></div><div>I'm sure there must be a g=
ood reason for this being defined as ill-formed in [dcl.init]/17b5...</div>=
<div><br></div><div> Otherwise, if the destination type i=
s an array, the program is ill-formed</div><div><br></div><div>...but I don=
't quite see what it is.<br></div><div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_675_16146603.1395380619611--
.
Author: David Krauss <potswa@gmail.com>
Date: Fri, 21 Mar 2014 17:42:51 +0800
Raw View
--Apple-Mail=_CDDBBF5D-B77F-4B41-A7EB-A17FEF6F22F9
Content-Type: text/plain; charset=ISO-8859-1
On 2014-03-21, at 1:43 PM, Andrew Tomazos <andrewtomazos@gmail.com> wrote:
> Why can't an object of type array of N T be initialized by an expression of type array of N T?
>
> int x[3] = {1, 2, 3};
>
> int y[3] = x; // ill-formed
>
> I'm sure there must be a good reason for this being defined as ill-formed in [dcl.init]/17b5...
>
> Otherwise, if the destination type is an array, the program is ill-formed
>
> ...but I don't quite see what it is.
Because it was ill-formed in C. Arrays cannot be rvalues; they prefer to decay to pointers.
I think initializer_list should be fixed to be user-initializable (e.g. by a range), rather than changing C compatibility.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--Apple-Mail=_CDDBBF5D-B77F-4B41-A7EB-A17FEF6F22F9
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;03–21, at 1:43 PM, Andrew Tomazos <<a href=3D"mailto:andrewt=
omazos@gmail.com">andrewtomazos@gmail.com</a>> wrote:</div><br class=3D"=
Apple-interchange-newline"><blockquote type=3D"cite"><div dir=3D"ltr">Why c=
an't an object of type array of N T be initialized by an expression of type=
array of N T?<div><br></div><div><div> int x[3] =3D {1, 2, 3}=
;</div><div><br></div><div> int y[3] =3D x; // ill-formed</div=
></div><div><br></div><div>I'm sure there must be a good reason for this be=
ing defined as ill-formed in [dcl.init]/17b5...</div><div><br></div><div>&n=
bsp; Otherwise, if the destination type is an array, the progra=
m is ill-formed</div><div><br></div><div>...but I don't quite see what it i=
s.<br></div></div></blockquote><div><br></div><div>Because it was ill-forme=
d in C. Arrays cannot be rvalues; they prefer to decay to pointers.</div><d=
iv><br></div><div>I think <font face=3D"Courier">initializer_list</font> sh=
ould be fixed to be user-initializable (e.g. by a range), rather than chang=
ing C compatibility.</div><div><br></div></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_CDDBBF5D-B77F-4B41-A7EB-A17FEF6F22F9--
.
Author: Johannes Schaub <schaub.johannes@googlemail.com>
Date: Fri, 21 Mar 2014 11:02:41 +0100
Raw View
2014-03-21 6:43 GMT+01:00 Andrew Tomazos <andrewtomazos@gmail.com>:
> Why can't an object of type array of N T be initialized by an expression of
> type array of N T?
>
> int x[3] = {1, 2, 3};
>
> int y[3] = x; // ill-formed
>
> I'm sure there must be a good reason for this being defined as ill-formed in
> [dcl.init]/17b5...
>
> Otherwise, if the destination type is an array, the program is
> ill-formed
>
> ...but I don't quite see what it is.
>
+1, IMO this should be made well-formed. Keeping compatibility with
ill-formed C programs seems pointless to me.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Johannes Schaub <schaub.johannes@googlemail.com>
Date: Fri, 21 Mar 2014 11:04:54 +0100
Raw View
2014-03-21 10:42 GMT+01:00 David Krauss <potswa@gmail.com>:
>
> On 2014-03-21, at 1:43 PM, Andrew Tomazos <andrewtomazos@gmail.com> wrote:
>
> Why can't an object of type array of N T be initialized by an expression of
> type array of N T?
>
> int x[3] = {1, 2, 3};
>
> int y[3] = x; // ill-formed
>
> I'm sure there must be a good reason for this being defined as ill-formed in
> [dcl.init]/17b5...
>
> Otherwise, if the destination type is an array, the program is
> ill-formed
>
> ...but I don't quite see what it is.
>
>
> Because it was ill-formed in C. Arrays cannot be rvalues; they prefer to
> decay to pointers.
>
We already have a special case for string literal initializers of char
arrays. Perhaps we can do the same for array initializers of arrays.
Since we have static type information, this should not incur any
runtime overhead.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 21 Mar 2014 12:10:38 +0200
Raw View
On 21 March 2014 12:04, Johannes Schaub <schaub.johannes@googlemail.com> wrote:
>> Why can't an object of type array of N T be initialized by an expression of
>> type array of N T?
>> int x[3] = {1, 2, 3};
>> int y[3] = x; // ill-formed
>> I'm sure there must be a good reason for this being defined as ill-formed in
>> [dcl.init]/17b5...
>> Otherwise, if the destination type is an array, the program is
>> ill-formed
>> ...but I don't quite see what it is.
>> Because it was ill-formed in C. Arrays cannot be rvalues; they prefer to
>> decay to pointers.
> We already have a special case for string literal initializers of char
> arrays. Perhaps we can do the same for array initializers of arrays.
> Since we have static type information, this should not incur any
> runtime overhead.
I can already write
array<int, 3> x = {1,2,3};
array<int, 3> y = x;
I'll stifle a massive *yawn* during any discussion to make such changes
to built-in arrays.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: Johannes Schaub <schaub.johannes@googlemail.com>
Date: Fri, 21 Mar 2014 11:18:29 +0100
Raw View
2014-03-21 11:10 GMT+01:00 Ville Voutilainen <ville.voutilainen@gmail.com>:
> On 21 March 2014 12:04, Johannes Schaub <schaub.johannes@googlemail.com> wrote:
>>> Why can't an object of type array of N T be initialized by an expression of
>>> type array of N T?
>>> int x[3] = {1, 2, 3};
>>> int y[3] = x; // ill-formed
>>> I'm sure there must be a good reason for this being defined as ill-formed in
>>> [dcl.init]/17b5...
>>> Otherwise, if the destination type is an array, the program is
>>> ill-formed
>>> ...but I don't quite see what it is.
>>> Because it was ill-formed in C. Arrays cannot be rvalues; they prefer to
>>> decay to pointers.
>> We already have a special case for string literal initializers of char
>> arrays. Perhaps we can do the same for array initializers of arrays.
>> Since we have static type information, this should not incur any
>> runtime overhead.
>
> I can already write
>
> array<int, 3> x = {1,2,3};
> array<int, 3> y = x;
>
> I'll stifle a massive *yawn* during any discussion to make such changes
> to built-in arrays.
>
It would likely also increase the usability of the array<T, N>
interface, because it would allow initializing with arrays
// z could come from somewhere else
int z[] = { 1, 2, 3 };
array<int, 3> x = { z };
I can imagine this would work in most (all?) implementations of
array<> with the pending proposal on builtin arrays.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: David Krauss <potswa@gmail.com>
Date: Fri, 21 Mar 2014 18:28:11 +0800
Raw View
--Apple-Mail=_810F5663-A8BA-4AE1-A422-BA2075BDB283
Content-Type: text/plain; charset=ISO-8859-1
On 2014-03-21, at 6:18 PM, Johannes Schaub <schaub.johannes@googlemail.com> wrote:
> It would likely also increase the usability of the array<T, N>
> interface, because it would allow initializing with arrays
>
> // z could come from somewhere else
> int z[] = { 1, 2, 3 };
> array<int, 3> x = { z };
>
> I can imagine this would work in most (all?) implementations of
> array<> with the pending proposal on builtin arrays.
I've never seen this occur in real life. Anyway it can already be done by a factory function.
template< typename t, std::size_t n >
constexpr std::array< t, n >
make_array( t const (& init)[ n ] ) {
std::array< t, n > ret;
std::copy( init, init + n, ret.begin() );
return ret;
}
Being fancy with pack expansion could even eliminate the initial default-initialization.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
--Apple-Mail=_810F5663-A8BA-4AE1-A422-BA2075BDB283
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;03–21, at 6:18 PM, Johannes Schaub <<a href=3D"mailto:schaub=
..johannes@googlemail.com">schaub.johannes@googlemail.com</a>> wrote:</di=
v><br class=3D"Apple-interchange-newline"><blockquote type=3D"cite">It woul=
d likely also increase the usability of the array<T, N><br>interface,=
because it would allow initializing with arrays<br><br> =
// z could come from somewhere else<br> int z[] =3D { 1, =
2, 3 };<br> array<int, 3> x =3D { z };<br><br>I can=
imagine this would work in most (all?) implementations of<br>array<>=
with the pending proposal on builtin arrays.<br></blockquote><div><br></di=
v><div>I’ve never seen this occur in real life. Anyway it can already=
be done by a factory function.</div><div><br></div><div><font face=3D"Cour=
ier">template< typename t, std::size_t n ></font></div><div><font fac=
e=3D"Courier">constexpr std::array< t, n ></font></div><div><font fac=
e=3D"Courier">make_array( t const (& init)[ n ] ) {</font></div><div><f=
ont face=3D"Courier"> std::array< t, n > ret;</font></di=
v><div><font face=3D"Courier"> std::copy( init, init + n, ret.=
begin() );</font></div><div><font face=3D"Courier"> return ret=
;</font></div><div><font face=3D"Courier">}</font></div></div><br><div>Bein=
g fancy with pack expansion could even eliminate the initial default-initia=
lization.</div><div><br></div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_810F5663-A8BA-4AE1-A422-BA2075BDB283--
.