Things C++ 20 Deliberately Broke

Steven Schveighoffer schveiguy at gmail.com
Tue Sep 27 01:54:19 UTC 2022


On 9/26/22 6:30 PM, Ola Fosheim Grøstad wrote:
> On Monday, 26 September 2022 at 22:15:49 UTC, Steven Schveighoffer wrote:
>> On 9/25/22 7:01 PM, Walter Bright wrote:
>>> https://docs.google.com/presentation/d/1HwLNSyHxy203eptO9cbTmr7CH23sBGtTrfOmJf9n0ug/edit?usp=sharing&resourcekey=0-GH5F3wdP7D4dmxvLdBaMvw 
>>>
>>>
>>>
>>> https://news.ycombinator.com/item?id=32969957
>>>
>>
>> From the document:
>>
>> > Math between disparate enums is deprecated
>>
>> Why? Why can't you add one enum to another when they are based on int, 
>> as long as it's typed as int?
>>
>> I'm honestly curious as to the problems this is solving.
> 
> Bugs. An enum is representant an enumeration or a set. You should not 
> mix those without a cast. C++ has the upgraded «enum class» for this. 
> You should usually use constexpr for constants.
> 
> 

I misremembered how enums work in (old) C/C++. But it seems really 
awkward to make it difficult to extract the real value. I also don't see 
a huge harm in it implicitly converting, as D has allowed.

I suppose using namespaces and constexpr, one can *almost* mimic the 
behavior. But it's still not a type.

It seems the intuitive behavior is not readily accessible with C++.

-Steve


More information about the Digitalmars-d mailing list