Topic: explicit conversion from enum class to its
Author: Tim <thaines.astro@gmail.com>
Date: Sat, 29 Oct 2016 16:55:09 -0700 (PDT)
Raw View
------=_Part_1999_1551261694.1477785309285
Content-Type: multipart/alternative;
boundary="----=_Part_2000_1717817825.1477785309286"
------=_Part_2000_1717817825.1477785309286
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
We already have explicit conversions for scoped enums (they aren't pretty,=
=20
though)
#include <type_traits>
enum class SkipUnused : bool {No, Yes};
void process(SkipUnused skipUnused) {
if (static_cast<std::underlying_type<SkipUnused>::type>(skipUnused)){}
}
On Saturday, October 29, 2016 at 4:51:12 PM UTC-5, Andrzej Krzemie=C5=84ski=
=20
wrote:
>
> Hi All,
>
> One of the nice safety features of enum classes is that they cannot be=20
> implicitly converted to their underlying type. However, do you think we=
=20
> would lose this safety feature if we allowed an explicit conversion to th=
e=20
> underlying type?
>
> I do not know of any practical use of explicit conversion operators excep=
t=20
> for the contextual conversion to bool. And it is only this conversion tha=
t=20
> I am interested in.
>
> It would be beneficial to have a unique Boolean type that would not be=20
> convertible to another unique Boolean type. One solution is to use an enu=
m=20
> class with `bool` as underlying type:
>
> enum class SkipUnused : bool { No, Yes };
> enum class SkipNeative : bool { No, Yes };
>
> void process(SkipUnused skipUnused)
> {
> if (skipUnused) // doesn't compile
> {}
> }
>
> Unfortunately, such enum-based type does not work with boolean=20
> expressions. It would we had an explicit conversion.
>
> Do you think, it would be acceptable to add such explicit conversion to=
=20
> the underlying type, for enum classes?
>
> Regards,
> &rzej;
>
--=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/8da39f5b-a120-4be6-b9fd-35b9e9a28889%40isocpp.or=
g.
------=_Part_2000_1717817825.1477785309286
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">We already have explicit conversions for scoped enums (the=
y aren't pretty, though)<div><br></div><div><div>#include <type_trai=
ts></div><div><br></div><div>enum class SkipUnused : bool {No, Yes};<br>=
</div><div><br></div><div>void process(SkipUnused skipUnused) {</div><div><=
span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>if (static_=
cast<std::underlying_type<SkipUnused>::type>(skipUnused)){}</di=
v><div>}</div><div><br></div><div><br></div>On Saturday, October 29, 2016 a=
t 4:51:12 PM UTC-5, Andrzej Krzemie=C5=84ski wrote:<blockquote class=3D"gma=
il_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid=
;padding-left: 1ex;"><div dir=3D"ltr">Hi All,<br><br>One of the nice safety=
features of enum classes is that they cannot be implicitly converted to th=
eir underlying type. However, do you think we would lose this safety featur=
e if we allowed an explicit conversion to the underlying type?<br><br>I do =
not know of any practical use of explicit conversion operators except for t=
he contextual conversion to bool. And it is only this conversion that I am =
interested in.<br><br>It would be beneficial to have a unique Boolean type =
that would not be convertible to another unique Boolean type. One solution =
is to use an enum class with `bool` as underlying type:<br><br><div style=
=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-=
style:solid;border-width:1px"><code><div><span style=3D"color:#008">enum</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#008">class</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#606">SkipUnused=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">:</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">bool</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span=
style=3D"color:#000"> </span><span style=3D"color:#606">No</span><span sty=
le=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D=
"color:#606">Yes</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#660">};</span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#008">enum</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">class</span><span style=3D"color:#000"> </span><span style=3D"color:=
#606">SkipNeative</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">bool</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"> </span><span style=3D"color:#606">N=
o</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#606">Yes</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">};</span><span style=3D"color:#000"><br><br></sp=
an><span style=3D"color:#008">void</span><span style=3D"color:#000"> proces=
s</span><span style=3D"color:#660">(</span><span style=3D"color:#606">SkipU=
nused</span><span style=3D"color:#000"> skipUnused</span><span style=3D"col=
or:#660">)</span><span style=3D"color:#000"><br></span><span style=3D"color=
:#660">{</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"=
color:#008">if</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">skipUnused</span><span style=3D"=
color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color=
:#800">// doesn't compile</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#660">{}</span><span style=3D"color:#000=
"><br></span><span style=3D"color:#660">}</span></div></code></div><br>Unfo=
rtunately, such enum-based type does not work with boolean expressions. It =
would we had an explicit conversion.<br><br>Do you think, it would be accep=
table to add such explicit conversion to the underlying type, for enum clas=
ses?<br><br>Regards,<br>&rzej;<br></div></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/8da39f5b-a120-4be6-b9fd-35b9e9a28889%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8da39f5b-a120-4be6-b9fd-35b9e9a28889=
%40isocpp.org</a>.<br />
------=_Part_2000_1717817825.1477785309286--
------=_Part_1999_1551261694.1477785309285--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 29 Oct 2016 17:31:15 -0700 (PDT)
Raw View
------=_Part_1448_120075116.1477787476050
Content-Type: multipart/alternative;
boundary="----=_Part_1449_1965648314.1477787476050"
------=_Part_1449_1965648314.1477787476050
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Saturday, October 29, 2016 at 5:51:12 PM UTC-4, Andrzej Krzemie=C5=84ski=
=20
wrote:
>
> Hi All,
>
> One of the nice safety features of enum classes is that they cannot be=20
> implicitly converted to their underlying type. However, do you think we=
=20
> would lose this safety feature if we allowed an explicit conversion to th=
e=20
> underlying type?
>
> I do not know of any practical use of explicit conversion operators excep=
t=20
> for the contextual conversion to bool. And it is only this conversion tha=
t=20
> I am interested in.
>
So, what you're asking for is if the underlying type of a strong enum is=20
`bool`, then that type can be contextually converted to `bool`. I don't=20
think it's worth adding a language feature for such an incredibly narrow=20
corner case.
--=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/c1b30ec0-cf34-4244-9fb5-028458f5d659%40isocpp.or=
g.
------=_Part_1449_1965648314.1477787476050
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Saturday, October 29, 2016 at 5:51:12 PM UTC-4, Andrzej=
Krzemie=C5=84ski wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr">Hi All,<br><br>One of the nice safety features of enum classes i=
s that they cannot be implicitly converted to their underlying type. Howeve=
r, do you think we would lose this safety feature if we allowed an explicit=
conversion to the underlying type?<br><br>I do not know of any practical u=
se of explicit conversion operators except for the contextual conversion to=
bool. And it is only this conversion that I am interested in.<br></div></b=
lockquote><div><br>So, what you're asking for is if the underlying type=
of a strong enum is `bool`, then that type can be contextually converted t=
o `bool`. I don't think it's worth adding a language feature for su=
ch an incredibly narrow corner case.</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/c1b30ec0-cf34-4244-9fb5-028458f5d659%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c1b30ec0-cf34-4244-9fb5-028458f5d659=
%40isocpp.org</a>.<br />
------=_Part_1449_1965648314.1477787476050--
------=_Part_1448_120075116.1477787476050--
.
Author: Daniel Frey <d.frey@gmx.de>
Date: Sun, 30 Oct 2016 02:40:19 +0200
Raw View
> On 29 Oct 2016, at 23:51, Andrzej Krzemie=C5=84ski <akrzemi1@gmail.com> w=
rote:
>=20
> I do not know of any practical use of explicit conversion operators excep=
t for the contextual conversion to bool. And it is only this conversion tha=
t I am interested in.
If all you need is boolean conversion, how about
template<typename E>
constexpr std::enable_if_t<std::is_enum_v<E>,bool> is(E e) noexcept
{
return e =3D=3D E(true);
}
to be used like
if(is(skipUnused)) { ... }
Instead of is(), you could also use operators, e.g.
+skipUnused
or
!skipUnused
(the latter might actually be sensible, but inconsistent if skipUnused itse=
lf is not convertible to bool)
There is a caveat with using boolean enums, i.e., if the user writes:
enum class SkipUnused { Yes, No };
(Note the order of the values).
There is no way for us to detect this, unless we explicitly would expect a =
value called Yes (or should it be YES or TRUE?) and change the above to
template<typename E>
constexpr std::enable_if_t<std::is_enum_v<E>,bool> is(E e) noexcept
{
return e =3D=3D E::Yes;
}
> Do you think, it would be acceptable to add such explicit conversion to t=
he underlying type, for enum classes?
If anything, it should be explicit for a type, not implicit for all enums. =
Maybe allowing something like:
enum class SkipUnused { No, Yes };
explicit constexpr SkipUnused::operator bool() =3D default;
or
explicit constexpr SkipUnused::operator bool() noexcept { return *this =
=3D=3D Yes; }
where *this refers to the enum value and Yes is in the scope of SkipUnused,=
hence no SkipUnused::Yes is needed. Something like a "member" of an enum c=
lass. This might also allow other conversions (explicitly), making a possib=
le proposal usable in more contexts. I'm not really sure it is worth it, th=
ough.
--=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/D44CA73E-022C-4803-8F52-F644679B996E%40gmx.de.
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 30 Oct 2016 08:50:16 +0100
Raw View
This is a multi-part message in MIME format.
--------------088B6F84F87115FA27FCC891
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=A9crit :
> Hi All,
>
> One of the nice safety features of enum classes is that they cannot be=20
> implicitly converted to their underlying type. However, do you think=20
> we would lose this safety feature if we allowed an explicit conversion=20
> to the underlying type?
>
> I do not know of any practical use of explicit conversion operators=20
> except for the contextual conversion to bool. And it is only this=20
> conversion that I am interested in.
This works already in a non-contextual conversion, isn't it?
bool(e)
I believe the missing contextual conversion merits an issue.
BTW, Boost.ScopedEnum emulation defined an explicit conversion on=20
compilers with them and without enum class.
>
> It would be beneficial to have a unique Boolean type that would not be=20
> convertible to another unique Boolean type. One solution is to use an=20
> enum class with `bool` as underlying type:
>
> |
> enumclassSkipUnused:bool{No,Yes};
> enumclassSkipNeative:bool{No,Yes};
>
> voidprocess(SkipUnusedskipUnused)
> {
> if(skipUnused)// doesn't compile
> {}
> }
> |
>
> Unfortunately, such enum-based type does not work with boolean=20
> expressions. It would we had an explicit conversion.
Well, this is a common problem due to the fact we are missing=20
strongly(opaque) types.
|
|
>
> Do you think, it would be acceptable to add such explicit conversion=20
> to the underlying type, for enum classes?
Given that the explicit cast to the underlying type works already, I=20
believe it is a reasonable feature, and I don't know what could be the=20
reason to don't define it. Maybe some know it.
SkipUnused e{};
if (bool(e))
std::cout << "Yes\n";
else
std::cout << "No\n";
When we want to be explicit without naming the type I would add a=20
function, but this is not your case.
template <typename E>
auto underlying(E e) { return static_cast<underlying_type_t<E>>(e); }
auto x =3D underlying(e);
Vicente
--=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/f380095f-96be-d02f-584b-6821f70a20b2%40wanadoo.f=
r.
--------------088B6F84F87115FA27FCC891
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 29/10/2016 =C3=A0 23:51, Andrzej
Krzemie=C5=84ski a =C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:4afed494-4fc5-4b06-b3e7-255aa293068e@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">Hi All,<br>
<br>
One of the nice safety features of enum classes is that they
cannot be implicitly converted to their underlying type.
However, do you think we would lose this safety feature if we
allowed an explicit conversion to the underlying type?<br>
<br>
I do not know of any practical use of explicit conversion
operators except for the contextual conversion to bool. And it
is only this conversion that I am interested in.<br>
</div>
</blockquote>
<br>
This works already in a non-contextual conversion, isn't it?<br>
<br>
=C2=A0=C2=A0=C2=A0 bool(e)<br>
<br>
I believe the missing contextual conversion merits an issue. <br>
<br>
BTW, Boost.ScopedEnum emulation defined an explicit conversion on
compilers with them and without enum class.<br>
<blockquote
cite=3D"mid:4afed494-4fc5-4b06-b3e7-255aa293068e@isocpp.org"
type=3D"cite">
<div dir=3D"ltr"><br>
It would be beneficial to have a unique Boolean type that would
not be convertible to another unique Boolean type. One solution
is to use an enum class with `bool` as underlying type:<br>
<br>
<div style=3D"background-color: rgb(250, 250, 250); border-color:
rgb(187, 187, 187); border-style: solid; border-width: 1px;
overflow-wrap: break-word;" class=3D"prettyprint"><code
class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #008;"
class=3D"styled-by-prettify">enum</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">class</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">SkipUnu=
sed</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-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">bool</s=
pan><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-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">No</spa=
n><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: #606;" class=3D"styled-by-prettify">Yes</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">};</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">enum</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">class</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">SkipNea=
tive</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-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">bool</s=
pan><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-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">No</spa=
n><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: #606;" class=3D"styled-by-prettify">Yes</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">};</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
<br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">void</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> proces=
s</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">SkipUnu=
sed</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
skipUnused</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: #660;"
class=3D"styled-by-prettify">{</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">if</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-by-prettify">skipUnu=
sed</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: #800;" class=3D"styled-by-prettify">//
doesn't compile</span><span style=3D"color: #000;"
class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 </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: #660;"
class=3D"styled-by-prettify">}</span></div>
</code></div>
<br>
Unfortunately, such enum-based type does not work with boolean
expressions. It would we had an explicit conversion.<br>
</div>
</blockquote>
Well, this is a common problem due to the fact we are missing
strongly(opaque) types.<br>
<code class=3D"prettyprint"><span style=3D"color: #660;"
class=3D"styled-by-prettify"><br>
<br>
</span></code>
<blockquote
cite=3D"mid:4afed494-4fc5-4b06-b3e7-255aa293068e@isocpp.org"
type=3D"cite">
<div dir=3D"ltr"><br>
Do you think, it would be acceptable to add such explicit
conversion to the underlying type, for enum classes?<br>
</div>
</blockquote>
Given that the explicit cast to the underlying type works already, I
believe it is a reasonable feature, and I don't know what could be
the reason to don't define it. Maybe some know it.<br>
<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SkipUnused e{};<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (bool(e)) <br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std:=
:cout << "Yes\n";<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else <br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std:=
:cout << "No\n";<br>
<br>
When we want to be explicit without naming the type I would add a
function, but this is not your case.<br>
<br>
template <typename E><br>
auto underlying(E e)=C2=A0 { return
static_cast<underlying_type_t<E>>(e); }<br>
<br>
auto x =3D underlying(e);<br>
<br>
Vicente<br>
</body>
</html>
<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/f380095f-96be-d02f-584b-6821f70a20b2%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f380095f-96be-d02f-584b-6821f70a20b2=
%40wanadoo.fr</a>.<br />
--------------088B6F84F87115FA27FCC891--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Sun, 30 Oct 2016 03:32:35 -0500
Raw View
On Sun, Oct 30, 2016 at 2:50 AM, Vicente J. Botet Escriba
<vicente.botet@wanadoo.fr> wrote:
>
> This works already in a non-contextual conversion, isn't it?
>
> bool(e)
>
> I believe the missing contextual conversion merits an issue.
I feel the same. At least this specific use case should work.
Currently contextually converted to bool requires direct
initialization from bool:
bool t(e);
I don't know of a case other than scoped enum where
explicit conversion to bool is supported but not
initialization, so maybe we could just fix contextually converted
to bool by querying for `bool(e)`.
Fixing scoped enum is a little bit more concerning
to me.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://blog.miator.net/
--
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/CAGsORuBKvEVOSOOyGtF0aHUMkZmYzjkDceiHnisb4_tyQ2Op3Q%40mail.gmail.com.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 30 Oct 2016 05:20:39 -0700 (PDT)
Raw View
------=_Part_1323_584620306.1477830040015
Content-Type: multipart/alternative;
boundary="----=_Part_1324_1011137650.1477830040015"
------=_Part_1324_1011137650.1477830040015
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, Vicente J. Botet Escriba=
=20
wrote:
>
> Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=A9crit :
>
> Hi All,
>
> One of the nice safety features of enum classes is that they cannot be=20
> implicitly converted to their underlying type. However, do you think we=
=20
> would lose this safety feature if we allowed an explicit conversion to th=
e=20
> underlying type?
>
> I do not know of any practical use of explicit conversion operators excep=
t=20
> for the contextual conversion to bool. And it is only this conversion tha=
t=20
> I am interested in.
>
>
> This works already in a non-contextual conversion, isn't it?
>
> bool(e)
>
No, it doesn't. The only way to convert a strongly typed enum to its=20
underlying type is with a `static_cast`.
--=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/1c81b80e-33b8-4de3-9bf7-94656e8b98f5%40isocpp.or=
g.
------=_Part_1324_1011137650.1477830040015
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, V=
icente J. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 29/10/2016 =C3=A0 23:51, Andrzej
Krzemie=C5=84ski a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">Hi All,<br>
<br>
One of the nice safety features of enum classes is that they
cannot be implicitly converted to their underlying type.
However, do you think we would lose this safety feature if we
allowed an explicit conversion to the underlying type?<br>
<br>
I do not know of any practical use of explicit conversion
operators except for the contextual conversion to bool. And it
is only this conversion that I am interested in.<br>
</div>
</blockquote>
<br>
This works already in a non-contextual conversion, isn't it?<br>
<br>
=C2=A0=C2=A0=C2=A0 bool(e)<br></div></blockquote><div><br>No, it doesn&=
#39;t. The only way to convert a strongly typed enum to its underlying type=
is with a `static_cast`.<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/1c81b80e-33b8-4de3-9bf7-94656e8b98f5%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1c81b80e-33b8-4de3-9bf7-94656e8b98f5=
%40isocpp.org</a>.<br />
------=_Part_1324_1011137650.1477830040015--
------=_Part_1323_584620306.1477830040015--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 30 Oct 2016 14:53:37 +0100
Raw View
This is a multi-part message in MIME format.
--------------5BF172B001C10234D4F00A99
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 30/10/2016 =C3=A0 13:20, Nicol Bolas a =C3=A9crit :
>
>
> On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, Vicente J. Botet=20
> Escriba wrote:
>
> Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=A9crit :
>> Hi All,
>>
>> One of the nice safety features of enum classes is that they
>> cannot be implicitly converted to their underlying type. However,
>> do you think we would lose this safety feature if we allowed an
>> explicit conversion to the underlying type?
>>
>> I do not know of any practical use of explicit conversion
>> operators except for the contextual conversion to bool. And it is
>> only this conversion that I am interested in.
>
> This works already in a non-contextual conversion, isn't it?
>
> bool(e)
>
>
> No, it doesn't. The only way to convert a strongly typed enum to its=20
> underlying type is with a `static_cast`.
It works for clang and gcc
http://melpon.org/wandbox/permlink/TnVrIdj3wz76l7b4
enum class SkipUnused : bool { No, Yes };
SkipUnused e{};
bool b1 {bool(e)}; (void)b1;
bool b2 =3Dbool(e); (void)b2;
b1 =3D bool(e);
if (bool(e))
std::cout << "Yes\n";
else
std::cout << "No\n";
Maybe there is a bug in both compilers ;-)
Vicente
--=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/74d02121-9633-b6d1-1187-2a9ab660089d%40wanadoo.f=
r.
--------------5BF172B001C10234D4F00A99
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 30/10/2016 =C3=A0 13:20, Nicol Bolas =
a
=C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:1c81b80e-33b8-4de3-9bf7-94656e8b98f5@isocpp.org"
type=3D"cite">
<div dir=3D"ltr"><br>
<br>
On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, Vicente J.
Botet Escriba wrote:
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=
=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">Hi All,<br>
<br>
One of the nice safety features of enum classes is that
they cannot be implicitly converted to their underlying
type. However, do you think we would lose this safety
feature if we allowed an explicit conversion to the
underlying type?<br>
<br>
I do not know of any practical use of explicit
conversion operators except for the contextual
conversion to bool. And it is only this conversion that
I am interested in.<br>
</div>
</blockquote>
<br>
This works already in a non-contextual conversion, isn't it?<br=
>
<br>
=C2=A0=C2=A0=C2=A0 bool(e)<br>
</div>
</blockquote>
<div><br>
No, it doesn't. The only way to convert a strongly typed enum
to its underlying type is with a `static_cast`.<br>
</div>
</div>
</blockquote>
<br>
It works for clang and gcc<br>
<br>
<a class=3D"moz-txt-link-freetext" href=3D"http://melpon.org/wandbox/pe=
rmlink/TnVrIdj3wz76l7b4">http://melpon.org/wandbox/permlink/TnVrIdj3wz76l7b=
4</a><br>
<br>
enum class SkipUnused : bool { No, Yes };<br>
<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 SkipUnused e{};<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bool b1 {bool(e)}; (void)b1;=
<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bool b2 =3Dbool(e); (void)b2=
;<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 b1 =3D bool(e);<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (bool(e)) <br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std:=
:cout << "Yes\n";<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else <br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std:=
:cout << "No\n";<br>
<br>
Maybe there is a bug in both compilers ;-)<br>
<br>
Vicente<br>
</body>
</html>
<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/74d02121-9633-b6d1-1187-2a9ab660089d%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/74d02121-9633-b6d1-1187-2a9ab660089d=
%40wanadoo.fr</a>.<br />
--------------5BF172B001C10234D4F00A99--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 30 Oct 2016 07:23:08 -0700 (PDT)
Raw View
------=_Part_1520_927821942.1477837388206
Content-Type: multipart/alternative;
boundary="----=_Part_1521_1776317284.1477837388206"
------=_Part_1521_1776317284.1477837388206
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sunday, October 30, 2016 at 9:53:41 AM UTC-4, Vicente J. Botet Escriba=
=20
wrote:
>
> Le 30/10/2016 =C3=A0 13:20, Nicol Bolas a =C3=A9crit :
>
>
>
> On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, Vicente J. Botet Escriba=
=20
> wrote:=20
>>
>> Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=A9crit :
>>
>> Hi All,
>>
>> One of the nice safety features of enum classes is that they cannot be=
=20
>> implicitly converted to their underlying type. However, do you think we=
=20
>> would lose this safety feature if we allowed an explicit conversion to t=
he=20
>> underlying type?
>>
>> I do not know of any practical use of explicit conversion operators=20
>> except for the contextual conversion to bool. And it is only this=20
>> conversion that I am interested in.
>>
>>
>> This works already in a non-contextual conversion, isn't it?
>>
>> bool(e)
>>
>
> No, it doesn't. The only way to convert a strongly typed enum to its=20
> underlying type is with a `static_cast`.
>
>
> It works for clang and gcc
>
So why doesn't it work when you use direct initialization of a variable=20
<http://ideone.com/hrMiy7> (like `bool b{e}`)? Direct initialization and=20
creating a temporary ought to work identically.
So if this is an issue, then I would say that the issue is the asymmetry=20
between direct initialization of enum classes and creating prvalues of them=
..
--=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/dc9396b6-00c6-4249-8988-a36f41c52519%40isocpp.or=
g.
------=_Part_1521_1776317284.1477837388206
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, October 30, 2016 at 9:53:41 AM UTC-4, Vicente J=
.. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 30/10/2016 =C3=A0 13:20, Nicol Bolas a
=C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr"><br>
<br>
On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, Vicente J.
Botet Escriba wrote:
<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=
=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">Hi All,<br>
<br>
One of the nice safety features of enum classes is that
they cannot be implicitly converted to their underlying
type. However, do you think we would lose this safety
feature if we allowed an explicit conversion to the
underlying type?<br>
<br>
I do not know of any practical use of explicit
conversion operators except for the contextual
conversion to bool. And it is only this conversion that
I am interested in.<br>
</div>
</blockquote>
<br>
This works already in a non-contextual conversion, isn't it=
?<br>
<br>
=C2=A0=C2=A0=C2=A0 bool(e)<br>
</div>
</blockquote>
<div><br>
No, it doesn't. The only way to convert a strongly typed enum
to its underlying type is with a `static_cast`.<br>
</div>
</div>
</blockquote>
<br>
It works for clang and gcc<br></div></blockquote><div><br>So why doesn&=
#39;t it work when you <a href=3D"http://ideone.com/hrMiy7">use direct init=
ialization of a variable</a> (like `bool b{e}`)? Direct initialization and =
creating a temporary ought to work identically.<br><br>So if this is an iss=
ue, then I would say that the issue is the asymmetry between direct initial=
ization of enum classes and creating prvalues of them.<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/dc9396b6-00c6-4249-8988-a36f41c52519%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/dc9396b6-00c6-4249-8988-a36f41c52519=
%40isocpp.org</a>.<br />
------=_Part_1521_1776317284.1477837388206--
------=_Part_1520_927821942.1477837388206--
.
Author: Peter Koch Larsen <peter.koch.larsen@gmail.com>
Date: Sun, 30 Oct 2016 15:33:13 +0100
Raw View
I believe bool(e) in that context was a C-style cast.
A small helper function would in my opinion be the best way out for
this purpose.
/Peter
On Sun, Oct 30, 2016 at 2:53 PM, Vicente J. Botet Escriba
<vicente.botet@wanadoo.fr> wrote:
> Le 30/10/2016 =C3=A0 13:20, Nicol Bolas a =C3=A9crit :
>
>
>
> On Sunday, October 30, 2016 at 3:50:18 AM UTC-4, Vicente J. Botet Escriba
> wrote:
>>
>> Le 29/10/2016 =C3=A0 23:51, Andrzej Krzemie=C5=84ski a =C3=A9crit :
>>
>> Hi All,
>>
>> One of the nice safety features of enum classes is that they cannot be
>> implicitly converted to their underlying type. However, do you think we
>> would lose this safety feature if we allowed an explicit conversion to t=
he
>> underlying type?
>>
>> I do not know of any practical use of explicit conversion operators exce=
pt
>> for the contextual conversion to bool. And it is only this conversion th=
at I
>> am interested in.
>>
>>
>> This works already in a non-contextual conversion, isn't it?
>>
>> bool(e)
>
>
> No, it doesn't. The only way to convert a strongly typed enum to its
> underlying type is with a `static_cast`.
>
>
> It works for clang and gcc
>
> http://melpon.org/wandbox/permlink/TnVrIdj3wz76l7b4
>
> enum class SkipUnused : bool { No, Yes };
>
> SkipUnused e{};
> bool b1 {bool(e)}; (void)b1;
> bool b2 =3Dbool(e); (void)b2;
> b1 =3D bool(e);
> if (bool(e))
> std::cout << "Yes\n";
> else
> std::cout << "No\n";
>
> Maybe there is a bug in both compilers ;-)
>
> Vicente
>
> --
> 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/74d02121-963=
3-b6d1-1187-2a9ab660089d%40wanadoo.fr.
--=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/CANPtknxi-106qkFiGieTUCB9w%3DyPwjip5-Nbukb2Ko_qZ=
36qbg%40mail.gmail.com.
.
Author: Andrzej Krzemienski <akrzemi1@gmail.com>
Date: Mon, 31 Oct 2016 09:14:59 +0100
Raw View
--e89a8fb1eae8d94dac054024cdb5
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
2016-10-30 2:31 GMT+02:00 Nicol Bolas <jmckesson@gmail.com>:
> On Saturday, October 29, 2016 at 5:51:12 PM UTC-4, Andrzej Krzemie=C5=84s=
ki
> wrote:
>>
>> Hi All,
>>
>> One of the nice safety features of enum classes is that they cannot be
>> implicitly converted to their underlying type. However, do you think we
>> would lose this safety feature if we allowed an explicit conversion to t=
he
>> underlying type?
>>
>> I do not know of any practical use of explicit conversion operators
>> except for the contextual conversion to bool. And it is only this
>> conversion that I am interested in.
>>
>
> So, what you're asking for is if the underlying type of a strong enum is
> `bool`, then that type can be contextually converted to `bool`. I don't
> think it's worth adding a language feature for such an incredibly narrow
> corner case.
>
> But are you saying that the process of pushing this change into the
language is too expensive to warrant the satisfaction of a marginal use
case? Or are you saying that satisfying one small use case is over-weighed
by potential type safety hole that would come with the change?
Regards,
&rzej;
--=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/CAOenAXg3vcFOkVFd8MWXuBeDE4rJhSK15SrK2KeAGZLBY4k=
POg%40mail.gmail.com.
--e89a8fb1eae8d94dac054024cdb5
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">2016-10-30 2:31 GMT+02:00 Nicol Bolas <span dir=3D"ltr"><<a href=3D"=
mailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>></=
span>:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bord=
er-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><span class=3D"">=
On Saturday, October 29, 2016 at 5:51:12 PM UTC-4, Andrzej Krzemie=C5=84ski=
wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8e=
x;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hi All,<br>=
<br>One of the nice safety features of enum classes is that they cannot be =
implicitly converted to their underlying type. However, do you think we wou=
ld lose this safety feature if we allowed an explicit conversion to the und=
erlying type?<br><br>I do not know of any practical use of explicit convers=
ion operators except for the contextual conversion to bool. And it is only =
this conversion that I am interested in.<br></div></blockquote></span><div>=
<br>So, what you're asking for is if the underlying type of a strong en=
um is `bool`, then that type can be contextually converted to `bool`. I don=
't think it's worth adding a language feature for such an incredibl=
y narrow corner case.</div></div><span class=3D"">
<p></p></span></blockquote><div>But are you saying that the process of push=
ing this change into the language is too expensive to warrant the satisfact=
ion of a marginal use case? Or are you saying that satisfying one small use=
case is over-weighed by potential type safety hole that would come with th=
e change?<br><br></div><div>Regards,<br></div><div>&rzej; <br></div></d=
iv><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/CAOenAXg3vcFOkVFd8MWXuBeDE4rJhSK15SrK=
2KeAGZLBY4kPOg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOenAXg3vcFOkVFd=
8MWXuBeDE4rJhSK15SrK2KeAGZLBY4kPOg%40mail.gmail.com</a>.<br />
--e89a8fb1eae8d94dac054024cdb5--
.