Topic: pros and cons of an 'explicit' type specifier to
Author: faisalv <faisalv@gmail.com>
Date: Sun, 2 Feb 2014 07:58:46 -0800 (PST)
Raw View
------=_Part_1394_1674045.1391356726035
Content-Type: text/plain; charset=UTF-8
I have a vague recollection of someone either proposing or discussing the
merits of disabling all implicit conversions (to and from?) by declaring a
variable or parameter as explicit.
For e.g.:
explicit unsigned int I = 'a'; // not ok.
explicit unsigned int I = 0U; // ok
I = 3U; //ok
I = 4LU; // not ok - long int -> int
unsigned int I2 = 'a'; // ok
int J = I; // not ok -> cannot use an explicitly declared variable to
convert implicitly from
int J = (int) I; // ok
int J = I2; // ok
explicit int J = I2; // not ok.
Does anyone know which isocpp-document talks about this approach?
Does anyone remember (or know) what the pros and cons of this approach are?
My sense is that this was probably discussed in the context of strong enums
and initializer list based initialization ...
Any pointers to the relevant documents or forum discussions will be
appreciated!
thank 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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1394_1674045.1391356726035
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I have a vague recollection of someone either proposing or=
discussing the merits of disabling all implicit conversions (to and from?)=
by declaring a variable or parameter as explicit.<br><br>For e.g.:<br><br>=
explicit unsigned int I =3D 'a'; // not ok.<br>explicit unsigned int I =3D =
0U; // ok<br>I =3D 3U; //ok<br>I =3D 4LU; // not ok - long int -> int<br=
><br>unsigned int I2 =3D 'a'; // ok<br><br>int J =3D I; // not ok -> can=
not use an explicitly declared variable to convert implicitly from<br>int J=
=3D (int) I; // ok<br><br>int J =3D I2; // ok<br>explicit int J =3D I2; //=
not ok.<br><br><br>Does anyone know which isocpp-document talks about this=
approach? <br>Does anyone remember (or know) what the pros and cons of thi=
s approach are?<br><br>My sense is that this was probably discussed in the =
context of strong enums and initializer list based initialization ...<br><b=
r>Any pointers to the relevant documents or forum discussions will be appre=
ciated!<br><br>thank you!<br><br><br><br> <br><br></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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_1394_1674045.1391356726035--
.