[SUGGESTION] C++0x concepts for cpp2 #591
Replies: 6 comments 15 replies
-
I was hoping to get some feedback to this issue. If Herb doesn't want that in cpp2, he can close but I'd like to see what his views are. |
Beta Was this translation helpful? Give feedback.
-
See https://youtu.be/CXn02MPkn8Y?t=176.
|
Beta Was this translation helpful? Give feedback.
-
First of all, THANKS for a reply. There's also notion of nominal concepts which are explicitly opt in. They can be easily emulated with interfaces (on cpp2 side) and std::derived_from (on cpp side) so that's one more thing. |
Beta Was this translation helpful? Give feedback.
-
Good question! It wasn't really so much that Bjarne didn't like C++0x concepts... Bjarne wanted C++0x concepts to succeed, despite their flaws and despite that they were a compromise design between his group and another group, and he was not happy that they didn't make it into C++11. The issues were that:
Also, a (the?) major operational difference between C++0x concepts and C++20 concepts is definition checking. Definition checking is definitely [sic] valuable, but remember the rule: There are way more readers than writers, way more users and authors, way more call sites than definitions. In this case, that means checking call sites delivers well over 99% of the mistake-diagnosing value of concepts (for popular concepts like those in |
Beta Was this translation helpful? Give feedback.
-
I disagree here. Absence of definition checking leads to problems. The easy one to think about is that a programmer can forget to put all the constraints on their function which leads us back to "before concept" era. It may continue to work for a long time until someone passes a paramater that violates that one specific missed contraint and everything falls apart. But the bigger problems that I think is that no defintion checking means that concepts do not propagate up. Edit: I really wanted to give a code example but couldn't get one. With defintion checking, concept propagation automatically happens and therefore all the errors you get are on the top level function. That's why I'd say that its defintion checking that delivers 99% of the mistake-diagnosing value of concepts. Without it, you have to hope that programmers won't make mistakes which we all know how it plays out. If there's one feature that I hope is implemented from this discussion, it would be defintion checking. Another discussion that I would want to get started is about structural vs nominal concepts. Structural concepts were right for cpp because there was so much code out there, but cpp2 doesn't have that problem so nominal concepts could be considered. Even I'm divided on this issue so idk. |
Beta Was this translation helpful? Give feedback.
-
This looks really promising. |
Beta Was this translation helpful? Give feedback.
-
Concepts in cpp20 have made generic programming easier but they still leave a lot to be desired, after all they are called concepts "lite" for a reason. P1900 describes some desired features from concepts. Along with those features, concepts are only that much useful as much as they used. Currently there is no mechanism to force the use of concepts too (which P1900 does not mention).
While this is not a full suggestion, it is more of a question if Herb would like a mechanism similar to C++0x concepts to be present in cpp2?
A lot of work was done on that feature, and it almost made it into the language except that it didn't (I don't know the reasons but Herb, as being someone from the commitee would probably know).
Alternatives considered : Interfaces in cpp2 could somehow emulate both nominal concepts and customisation points but features like associated types, type erasure are still left desired.
Beta Was this translation helpful? Give feedback.
All reactions