September 26, 2022

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.

September 26, 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

September 27, 2022

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.

-Steve

Two disparate enums are not the same type and they are not int. Like feet and meters are both represented using float.

So C++20 take on this is if you want to do math between disparate enums you must explicitly cast to a common type like int, which states clearly on the page and to the compiler you know what you're doing.

September 27, 2022

On Tuesday, 27 September 2022 at 01:54:19 UTC, Steven Schveighoffer wrote:

>

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.

Hm, do you mean enums or constexpr? Constexpr constants are usually put inside a class. So you access them as ClassName::constant_name. C++20 also allows accessing enums through the class scope by allowing the using statement to apply to enums inside a class definition. So you can certainly build an enum like type with more advanced features than regular enums in C++. You can do it with enums, or without enums.

You can use enums to create new nominal integers. An example of this is std::byte which is defined like this:

enum class byte : unsigned char {} ;

As a result you cannot use operators on a byte and you now have a type for unassuming octets. You can do this for your own integer-based type quite easily and define the operations you want.

>

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

The intuitive behaviour for an enumeration are the operations: comparison, successor, predecessor.

It gets a bit messier in C/C++ as you also tend to use it for bitsets. Which probably should be a different concept. Anyway, I've started to use enum class for almost everything and then define overloaded set-functions that work on them. That way you encapsulate the casting and bit manipulation and hopefully get fewer bugs as a result.

September 28, 2022

On Monday, 26 September 2022 at 08:32:27 UTC, Siarhei Siamashka wrote:

>

On Monday, 26 September 2022 at 03:24:57 UTC, norm wrote:

>

If Python developers decided to keep both Python2 and Python3
maintained forever, then it would be similar to C++ and Rust.

Not at all. Python 2/3 is a split with incompatibilities. C++ is a deprecation + removal model except for very, very few exceptions. You can compile C++98 code in a C++20 compiler almost without any change.

September 29, 2022

On Wednesday, 28 September 2022 at 19:43:34 UTC, German Diago wrote:

>

On Monday, 26 September 2022 at 08:32:27 UTC, Siarhei Siamashka wrote:

>

On Monday, 26 September 2022 at 03:24:57 UTC, norm wrote:

>

If Python developers decided to keep both Python2 and Python3
maintained forever, then it would be similar to C++ and Rust.

Not at all. Python 2/3 is a split with incompatibilities.

These were not fatal incompatibilities though. Single-source Python 2/3 compatible code used to be a thing:

Of course having two slightly incompatible variants of the programming language is not ideal. That's surely some extra work for compiler/interpreter developers and also extra work for popular libraries developers. But application developers didn't have any urgency to waste resources on migrating their existing Python2 code to Python3 and instead could focus on delivering amazing features to their users.

Is the convenience of 1 compiler developer or the convenience of 1000 application developers more important for a programming language? The answer depends on many factors. And the size of the existing ecosystem is one of them.

>

C++ is a deprecation + removal model except for very, very few exceptions. You can compile C++98 code in a C++20 compiler almost without any change.

You can surely compile a simplistic C++98 helloworld code by a C++20 compiler with no changes at all. But Chromium developers couldn't easily compile their C++17 code by a C++20 compiler. That's exactly what this forum thread is all about. The key difference is that Chromium is a huge project.

C++ language has multiple supported versions of the language standard for a reason and this is a lifesaver for the projects with huge codebases, which have to be maintained over the span of many years or decades. If C++ compilers decided to drop support for the older versions of the language standard, then this would be similar to what Python did.

September 29, 2022

On Thursday, 29 September 2022 at 02:57:33 UTC, Siarhei Siamashka wrote:

>

But Chromium developers couldn't easily compile their C++17 code by a C++20 compiler.

Wasn't most of the issues compiler warnings?

1 2
Next ›   Last »