Topic: Allow calling any contructor for all array elements
Author: =?UTF-8?Q?Iv=C3=A1n_Sanz?= <ivansanzcarasa@gmail.com>
Date: Sun, 4 Feb 2018 09:29:12 -0800 (PST)
Raw View
------=_Part_421_88874367.1517765352432
Content-Type: multipart/alternative;
boundary="----=_Part_422_2067017041.1517765352432"
------=_Part_422_2067017041.1517765352432
Content-Type: text/plain; charset="UTF-8"
After some investigation, looks like the behavior initializing variables
follows some well-defined convention.
For single element:
new int; // random
new int(); // 0 (default initializer)
new int(23); // 23 (copy initializer)
new Test; // default contructor
new Test(...); // X constructor (overload-chosen)
This makes a lot of sense, until you try to apply the same logic on arrays:
new int[10]; // all random - OK
new int[10](); // all 0 (default initializer) - OK
new int[10](23); // all 23 (copy initializer on all) - NOT IMPLEMENTED
new Test[10]; // default contructors - OK
new Test[10](); // default contructors - OK
new Test[10](...); // X constructor on all (overload-chosen) - NOT
IMPLEMENTED
My logic says that you can make some assumptions:
If a type can be constructed using `T(Args..)` then every element from the
array can be constructed. There is no reason to not allow `T[N](Args...)`
syntax.
Why this feature doesn't exist? It would be very nice to allow
new int[10](23); // all 23
new Test[10]("asd", 123); // construct all using Test("asd", 123)
--
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/5388a0fb-588a-47b5-aebe-338a2d73c84e%40isocpp.org.
------=_Part_422_2067017041.1517765352432
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">After some investigation, looks like the behavior initiali=
zing variables follows some well-defined convention.<br><br>For single elem=
ent:<br><br>=C2=A0=C2=A0=C2=A0 new int; // random<br>=C2=A0=C2=A0=C2=A0 new=
int(); // 0 (default initializer)<br>=C2=A0=C2=A0=C2=A0 new int(23); // 23=
(copy initializer)<br><br>=C2=A0=C2=A0=C2=A0 new Test; // default contruct=
or<br>=C2=A0=C2=A0=C2=A0 new Test(...); // X constructor (overload-chosen)<=
br><br>This makes a lot of sense, until you try to apply the same logic on =
arrays:<br><br>=C2=A0=C2=A0=C2=A0 new int[10]; // all random - OK<br>=C2=A0=
=C2=A0=C2=A0 new int[10](); // all 0 (default initializer) - OK<br>=C2=A0=
=C2=A0=C2=A0 new int[10](23); // all 23 (copy initializer on all) - NOT IMP=
LEMENTED<br><br>=C2=A0=C2=A0=C2=A0 new Test[10]; // default contructors - O=
K<br>=C2=A0=C2=A0=C2=A0 new Test[10](); // default contructors - OK<br>=C2=
=A0=C2=A0=C2=A0 new Test[10](...); // X constructor on all (overload-chosen=
) - NOT IMPLEMENTED<br><br>My logic says that you can make some assumptions=
:<br>If a type can be constructed using `T(Args..)` then every element from=
the array can be constructed. There is no reason to not allow `T[N](Args..=
..)` syntax.<br><br>Why this feature doesn't exist? It would be very nic=
e to allow<br><br>=C2=A0=C2=A0=C2=A0 new int[10](23); // all 23<br>=C2=A0=
=C2=A0=C2=A0 new Test[10]("asd", 123); // construct all using Tes=
t("asd", 123)<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/5388a0fb-588a-47b5-aebe-338a2d73c84e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5388a0fb-588a-47b5-aebe-338a2d73c84e=
%40isocpp.org</a>.<br />
------=_Part_422_2067017041.1517765352432--
------=_Part_421_88874367.1517765352432--
.
Author: =?UTF-8?Q?Iv=C3=A1n_Sanz?= <ivansanzcarasa@gmail.com>
Date: Sun, 4 Feb 2018 09:30:23 -0800 (PST)
Raw View
------=_Part_2710_1578036264.1517765424094
Content-Type: multipart/alternative;
boundary="----=_Part_2711_815226094.1517765424094"
------=_Part_2711_815226094.1517765424094
Content-Type: text/plain; charset="UTF-8"
Other discussion threads:
https://stackoverflow.com/questions/48610895/allow-calling-any-contructor-for-all-array-elements
https://www.reddit.com/r/cpp/comments/7v80pe/why_doesnt_c_allow_calling_any_contructor_for_all/
--
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/adec0f91-9155-4cd6-8bfa-310c5a02d291%40isocpp.org.
------=_Part_2711_815226094.1517765424094
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Other discussion threads:</div><div><br></div><div>ht=
tps://stackoverflow.com/questions/48610895/allow-calling-any-contructor-for=
-all-array-elements</div><div>https://www.reddit.com/r/cpp/comments/7v80pe/=
why_doesnt_c_allow_calling_any_contructor_for_all/<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/adec0f91-9155-4cd6-8bfa-310c5a02d291%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/adec0f91-9155-4cd6-8bfa-310c5a02d291=
%40isocpp.org</a>.<br />
------=_Part_2711_815226094.1517765424094--
------=_Part_2710_1578036264.1517765424094--
.
Author: Bo Persson <bop@gmb.dk>
Date: Sun, 4 Feb 2018 19:31:34 +0100
Raw View
On 2018-02-04 18:29, Iv=C3=A1n Sanz wrote:
> After some investigation, looks like the behavior initializing variables=
=20
> follows some well-defined convention.
>=20
> For single element:
>=20
> =C2=A0=C2=A0=C2=A0 new int; // random
> =C2=A0=C2=A0=C2=A0 new int(); // 0 (default initializer)
> =C2=A0=C2=A0=C2=A0 new int(23); // 23 (copy initializer)
>=20
> =C2=A0=C2=A0=C2=A0 new Test; // default contructor
> =C2=A0=C2=A0=C2=A0 new Test(...); // X constructor (overload-chosen)
>=20
> This makes a lot of sense, until you try to apply the same logic on array=
s:
>=20
> =C2=A0=C2=A0=C2=A0 new int[10]; // all random - OK
> =C2=A0=C2=A0=C2=A0 new int[10](); // all 0 (default initializer) - OK
> =C2=A0=C2=A0=C2=A0 new int[10](23); // all 23 (copy initializer on all) =
- NOT IMPLEMENTED
>=20
> =C2=A0=C2=A0=C2=A0 new Test[10]; // default contructors - OK
> =C2=A0=C2=A0=C2=A0 new Test[10](); // default contructors - OK
> =C2=A0=C2=A0=C2=A0 new Test[10](...); // X constructor on all (overload-=
chosen) - NOT=20
> IMPLEMENTED
>=20
> My logic says that you can make some assumptions:
> If a type can be constructed using `T(Args..)` then every element from=20
> the array can be constructed. There is no reason to not allow=20
> `T[N](Args...)` syntax.
>=20
> Why this feature doesn't exist? It would be very nice to allow
>=20
> =C2=A0=C2=A0=C2=A0 new int[10](23); // all 23
> =C2=A0=C2=A0=C2=A0 new Test[10]("asd", 123); // construct all using Test=
("asd", 123)
>=20
This might fall under the "Don't try to fix C-style arrays"-principle,=20
which got us std::vector and std::array as replacements.
If you can do
new int[10](23); // all 23
then why can't we then do this without 'new'?
int a[10](23); // What happens here?
or
int a[10] =3D {23}; //??
Bo Persson
--=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/p57je9%24ee9%241%40blaine.gmane.org.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Sun, 04 Feb 2018 11:15:37 -0800
Raw View
On Sunday, 4 February 2018 10:31:34 PST Bo Persson wrote:
> then why can't we then do this without 'new'?
>
> int a[10](23); // What happens here?
>
> or
>
> int a[10] = {23}; //??
The latter one *can* be done. It's a valid syntax.
But it initialises the first element to 23 and the rest are default
initialised.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--
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/2131613.72VRamjx6x%40tjmaciei-mobl1.
.