Skip to content

[QUESTION] Metaclasses to be provided by default #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AbhinavK00 opened this issue Mar 21, 2023 · 1 comment
Closed

[QUESTION] Metaclasses to be provided by default #286

AbhinavK00 opened this issue Mar 21, 2023 · 1 comment

Comments

@AbhinavK00
Copy link

After reading Herb's P0707, I just wanted to ask which one of the metaclass examples provided in the paper are planned for cpp2.
Herb has already mentioned in #277 that he has planned for safe_union, flag_enum and regular enum. I guess that interface would also be provided andfinal probably won't be there as we can mark methods as final and that'll do enough to not have the metaclass (or shouldn't final be a specifier for the class definition instead of a metaclass itself?).
Also, will those metaclasses be in a some namespace?

Next up, the suggestion. I was originally going to suggest 3 language built-in (for some day that cpp2 gets its own compiler), one of those was same as safe_union that is planned but with only one difference. So, instead of having 2 different safe and unsafe types, maybe there could be only one type that is safe by default but using a supress block, we can do unsafe operations on it. Is that feasible? If yes, maybe it could be considered.

Next up, we can have a language inbuilt tuple which, like safe_union a cpp2 version of standard library type. We can name the members of this tuple and it may serve as a replacement for both std::tuple and C-like structs (since there is no need of classes or struct, we have cpp2's type).

Third one is a language built in array, current std::array is just a wrapper class around C-array and since cpp2 doesn't have to worry about C, we can have our own better behaved type like with bounds checking and a supress block to turn off bounds checking (not just specific to this type but for others too). Simple arrays could default to this new type instead of a C - array and string literals could just default to string literals can default this new type of char instead of const char*, a type which has no knowledge of size of string stored in it.
Basically, I'm asking for a std::array but in core language.
The reason for third one is about having to move away from std::initializer_list, inbuilt language arrays would be a simple replacement to those (i guess? pls guide me)

@hsutter
Copy link
Owner

hsutter commented Mar 23, 2023

The short answer is that I'm looking to start with about half of the ones listed in P0707. Note that initially they will be hardwired into the compiler... compile-time reflection and generation is farther down the road.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants