Topic: Make scoped enums contextually convertible to bool?
Author: "Ivan G." <nekotekina@gmail.com>
Date: Fri, 5 Oct 2018 04:45:29 -0700 (PDT)
Raw View
------=_Part_726_354067689.1538739929237
Content-Type: multipart/alternative;
boundary="----=_Part_727_1946911267.1538739929237"
------=_Part_727_1946911267.1538739929237
Content-Type: text/plain; charset="UTF-8"
This seems useful to test bits in "bitset" scoped enums (with proper
overloaded operators).
Existing topic:
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/Zp-KjArhS80
But it asks only about underlying bool type for some reason. Maybe there
are more of them.
Contextual conversion to bool would compare the underlying value with zero.
The problems with workarounds:
1) Overloading !, &&, or || is considered a bad practice and is still
incomplete.
2) Overloading unary + seems even worse, because it breaks expectations.
3) Writing a function seems better, but is too verbose.
4) Overload a & to return a class which converts both to bool
(contextually) and the enum value. May break expectations too because it
doesn't return an enum class directly.
Unfortunately, allowing contextual bool conversion by default seems
dangerous too - the simplest enum use case just lists various values but
doesn't assume that [first] one which equals to zero is anything special.
Maybe there is a proposal somewhere to allow declaring conversion operators
as global ones? So the programmer could specify a desired behaviour
directly.
--
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/490da838-ed69-4d41-badb-44937b876098%40isocpp.org.
------=_Part_727_1946911267.1538739929237
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>This seems useful to test bits in "bitset" =
scoped enums (with proper overloaded operators).</div><div><br></div><div>E=
xisting topic: https://groups.google.com/a/isocpp.org/forum/#!topic/std-pro=
posals/Zp-KjArhS80<br></div><div>But it asks only about underlying bool typ=
e for some reason. Maybe there are more of them.</div><div>Contextual conve=
rsion to bool would compare the underlying value with zero.</div><div><br><=
/div><div>The problems with workarounds:</div><div>1) Overloading !, &&=
amp;, or || is considered a bad practice and is still incomplete.</div><div=
>2) Overloading unary + seems even worse, because it breaks expectations.</=
div><div>3) Writing a function seems better, but is too verbose.</div><div>=
4) Overload a & to return a class which converts both to bool (contextu=
ally) and the enum value. May break expectations too because it doesn't=
return an enum class directly.</div><div><br></div><div>Unfortunately, all=
owing contextual bool conversion by default seems dangerous too - the simpl=
est enum use case just lists various values but doesn't assume that [fi=
rst] one which equals to zero is anything special.</div><div><br></div><div=
>Maybe there is a proposal somewhere to allow declaring conversion operator=
s as global ones? So the programmer could specify a desired behaviour direc=
tly.</div><div><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/490da838-ed69-4d41-badb-44937b876098%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/490da838-ed69-4d41-badb-44937b876098=
%40isocpp.org</a>.<br />
------=_Part_727_1946911267.1538739929237--
------=_Part_726_354067689.1538739929237--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Fri, 05 Oct 2018 20:08:12 +0000
Raw View
This is a multi-part message in MIME format.
--b1_585b4cc878aad4d0ea9c8a789c48d6d1
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Comparing to zero is not always the behavior you
want. I seriously consider that scoped enum should
support member functions, so that you can write
a =E2=80=9Cexplicit operator bool()=E2=80=9D by yourself.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________
From: Ivan G. <nekotekina@gmail.com>
Sent: Friday, October 5, 2018 6:45 AM
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Subject: [std-proposals] Make scoped enums contextually convertible to bool=
?
This seems useful to test bits in "bitset" scoped enums (with proper overlo=
aded operators).
Existing topic: https://groups.google.com/a/isocpp.org/forum/#!topic/std-pr=
oposals/Zp-KjArhS80
But it asks only about underlying bool type for some reason. Maybe there ar=
e more of them.
Contextual conversion to bool would compare the underlying value with zero.
--=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/nQLliUchVgW83GuDsKshEC1zUzS9-hQfrf1gTpRlUq83Njz4=
wo6Bv1qr7WxiNrzGL-BUUhLEqJNO0E5HSESzdt7rwRslPo41pQgdwWwO190%3D%40miator.net=
..
--b1_585b4cc878aad4d0ea9c8a789c48d6d1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<html><head></head><body><div class=3D"WordSection1"><p class=3D"MsoNormal"=
>Comparing to zero is not always the behavior you<br/>want.=C2=A0 I serious=
ly consider that scoped enum should<br/>support member functions, so that y=
ou can write<br/>a =E2=80=9Cexplicit operator bool()=E2=80=9D by yourself.<=
o:p></o:p></p><p class=3D"MsoNormal"><o:p>=C2=A0</o:p></p><p class=3D"MsoNo=
rmal">--<br/>Zhihao Yuan, ID lichray<br/>The best way to predict the future=
is to invent it.<br/>_______________________________________________<o:p><=
/o:p></p><p class=3D"MsoNormal"><o:p>=C2=A0</o:p></p><div style=3D"border:n=
one;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style=
=3D"border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in"><=
p class=3D"MsoNormal"><b>From:</b> Ivan G. <nekotekina@gmail.com> <br=
/><b>Sent:</b> Friday, October 5, 2018 6:45 AM<br/><b>To:</b> ISO C++ Stand=
ard - Future Proposals <std-proposals@isocpp.org><br/><b>Subject:</b>=
[std-proposals] Make scoped enums contextually convertible to bool?<o:p></=
o:p></p></div></div><p class=3D"MsoNormal"><o:p>=C2=A0</o:p></p><div><div><=
p class=3D"MsoNormal">This seems useful to test bits in "bitset" sc=
oped enums (with proper overloaded operators).<o:p></o:p></p></div><div><p =
class=3D"MsoNormal"><o:p>=C2=A0</o:p></p></div><div><p class=3D"MsoNormal">=
Existing topic: <a href=3D"https://groups.google.com/a/isocpp.org/forum/#!t=
opic/std-proposals/Zp-KjArhS80">https://groups.google.com/a/isocpp.org/foru=
m/#!topic/std-proposals/Zp-KjArhS80</a><o:p></o:p></p></div><div><p class=
=3D"MsoNormal">But it asks only about underlying bool type for some reason.=
Maybe there are more of them.<o:p></o:p></p></div><div><p class=3D"MsoNorm=
al">Contextual conversion to bool would compare the underlying value with z=
ero.<o:p></o:p></p></div></div></div></div></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/nQLliUchVgW83GuDsKshEC1zUzS9-hQfrf1gT=
pRlUq83Njz4wo6Bv1qr7WxiNrzGL-BUUhLEqJNO0E5HSESzdt7rwRslPo41pQgdwWwO190%3D%4=
0miator.net?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/nQLliUchVgW83GuDsKshEC1zUzS9-hQfrf1gT=
pRlUq83Njz4wo6Bv1qr7WxiNrzGL-BUUhLEqJNO0E5HSESzdt7rwRslPo41pQgdwWwO190%3D%4=
0miator.net</a>.<br />
--b1_585b4cc878aad4d0ea9c8a789c48d6d1--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Fri, 5 Oct 2018 15:57:44 -0700 (PDT)
Raw View
------=_Part_957_1869690890.1538780264124
Content-Type: multipart/alternative;
boundary="----=_Part_958_1971536235.1538780264124"
------=_Part_958_1971536235.1538780264124
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Friday, October 5, 2018 at 4:08:25 PM UTC-4, Zhihao Yuan wrote:
>
> Comparing to zero is not always the behavior you
> want. I seriously consider that scoped enum should
> support member functions, so that you can write
> a =E2=80=9Cexplicit operator bool()=E2=80=9D by yourself.
>
+1 for this.
enum Classes are pretty awkward to use in many contexts. I don't know if=20
they really thought through the use cases that well.
One common way to want to use them is for a set of flags. You can write all=
=20
of the boolean operators. YOu can even write a operator!() to negate it.=20
But you can't write an operator bool(), which makes it awkward.\
At a minimum, just operator bool() for scoped enums would be great.
--=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/b1818ea3-53f8-491d-b283-f3da6a04e637%40isocpp.or=
g.
------=_Part_958_1971536235.1538780264124
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, October 5, 2018 at 4:08:25 PM UTC-4, Zh=
ihao Yuan wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div><div><p c=
lass=3D"MsoNormal">Comparing to zero is not always the behavior you<br>want=
..=C2=A0 I seriously consider that scoped enum should<br>support member func=
tions, so that you can write<br>a =E2=80=9Cexplicit operator bool()=E2=80=
=9D by yourself.</p></div></div></blockquote><div><br></div><div>+1 for thi=
s.</div><div><br></div><div>enum Classes are pretty awkward to use in many =
contexts. I don't know if they really thought through the use cases tha=
t well.</div><div><br></div><div>One common way to want to use them is for =
a set of flags. You can write all of the boolean operators. YOu can even wr=
ite a operator!() to negate it. But you can't write an operator bool(),=
which makes it awkward.\</div><div><br></div><div>At a minimum, just opera=
tor bool() for scoped enums would be great.<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/b1818ea3-53f8-491d-b283-f3da6a04e637%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b1818ea3-53f8-491d-b283-f3da6a04e637=
%40isocpp.org</a>.<br />
------=_Part_958_1971536235.1538780264124--
------=_Part_957_1869690890.1538780264124--
.