Earlier quoted context omitted.
That's not C++.
Any reader who comment here hopefully has enough knowledge to understand the implied C++. struct Add {} std::variant Expr; OR class Expr {} class Add : Expr {}
Enum class improvements for C++17, C++20 and C++23
111–120 of 121 posts
Re: Enum class improvements for C++17, C++20 and C++23
#112Earlier quoted context omitted.
You should probably look up what a sum type is, it has nothing to do with summations. Your example doesn't contain a sum type. A C++ example: std:variant sum_type_instance = 5;
You seem to have a very narrow C++ view of what sum types are. Sum types are related to the expression problem, and the given example is the canonical instance of the expression problem. https://en.wikipedia.org/wiki/Expression_problem
Re: Enum class improvements for C++17, C++20 and C++23
#113Earlier quoted context omitted.
You seem to have a very narrow C++ view of what sum types are. Sum types are related to the expression problem, and the given example is the canonical instance of the expression problem. https://en.wikipedia.org/wiki/Expression_problem
Sum types are not “anything that can encode an expression”. They have a precise definition. They are closed and a synonym for a tagged union.
Re: Enum class improvements for C++17, C++20 and C++23
#114Earlier quoted context omitted.
Sum types are not “anything that can encode an expression”. They have a precise definition. They are closed and a synonym for a tagged union.
Please use quotes to refer to a statement that someone has actually made. Doing otherwise is an indicator that you are making a strawman argument.
Re: Enum class improvements for C++17, C++20 and C++23
#115Earlier quoted context omitted.
Please use quotes to refer to a statement that someone has actually made. Doing otherwise is an indicator that you are making a strawman argument.
Today you learned what a sum type is. Just admit your ignorance and move on with your life. Maybe bookmark this: https://en.wikipedia.org/wiki/Tagged_union
Re: Enum class improvements for C++17, C++20 and C++23
#116Earlier quoted context omitted.
You seem to have a very narrow C++ view of what sum types are. Sum types are related to the expression problem, and the given example is the canonical instance of the expression problem. https://en.wikipedia.org/wiki/Expression_problem
Sum types are not “anything that can encode an expression”. They have a precise definition. They are closed and a synonym for a tagged union.
Tagged unions are an implementation and one that's often a poor fit for the problem. Sum types are an idea from type theory, rather than an implementation detail. It's very on-brand for C++ to have standardized a poor implementation detail rather than the useful idea.
Look at how much hoop jumping was required to make std::optional work for C++ 26 and then compare how Rust's Option isn't even special, that's just naturally what happens.
Re: Enum class improvements for C++17, C++20 and C++23
#117Earlier quoted context omitted.
Sum types are not “anything that can encode an expression”. They have a precise definition. They are closed and a synonym for a tagged union.
"synonym for a tagged union" Tagged unions are an implementation and one that's often a poor fit for the problem. Sum types are an idea from type theory, rather than an implementation detail. It's very on-brand for C++ to have standardized a poor implementation detail rather than the useful idea. Look at how much hoop jumping was required to make std::optional work for C++ 26 and then compare how Rust's Option isn't…
> In computer science, a tagged union, also called a variant, variant record, choice type, discriminated union, disjoint union, sum type, or coproduct, is a data structure used to hold a value that could take on several different, but fixed, types. [1]
C++ class inheritance is not a sum type for a couple reasons:
- It does not allow you to discriminate on the type.
- You can add RTTI, which allows you to discriminate, but then it is not a fixed set of types.
Obviously, Rust does sum types better than C++, but that is really irrelevant.
Re: Enum class improvements for C++17, C++20 and C++23
#118Earlier quoted context omitted.
"synonym for a tagged union" Tagged unions are an implementation and one that's often a poor fit for the problem. Sum types are an idea from type theory, rather than an implementation detail. It's very on-brand for C++ to have standardized a poor implementation detail rather than the useful idea. Look at how much hoop jumping was required to make std::optional work for C++ 26 and then compare how Rust's Option isn't…
These are all synonyms, even in type theory: > In computer science, a tagged union, also called a variant, variant record, choice type, discriminated union, disjoint union, sum type, or coproduct, is a data structure used to hold a value that could take on several different, but fixed, types. [1] C++ class inheritance is not a sum type for a couple reasons: - It does not allow you to discriminate on the type. - You c…
Re: Enum class improvements for C++17, C++20 and C++23
#119Earlier quoted context omitted.
My guess currently is that C++ 29 will get some sort of pattern matching. It's too big a feature to board the C++ 26 train in autumn 2024 and there's nowhere close to consensus on how it should work or how it's spelled yet. So, assume C++ 29 has pattern matching. That causes people to attempt various idiomatic constructions from languages which always had pattern matching, and of course they're all rather awkward in…
There are two competing pattern matching proposals, hopefully they'll converge soon.
Re: Enum class improvements for C++17, C++20 and C++23
#120Earlier quoted context omitted.
These are all synonyms, even in type theory: > In computer science, a tagged union, also called a variant, variant record, choice type, discriminated union, disjoint union, sum type, or coproduct, is a data structure used to hold a value that could take on several different, but fixed, types. [1] C++ class inheritance is not a sum type for a couple reasons: - It does not allow you to discriminate on the type. - You c…
It's true, in the "Encyclopedia anyone can edit" you will find that quote.