3 ms·
This feature will greatly simplify CRTP while also making it safer and more powerful. It will also remove the need to of multiple pointless copy pasted overloa
by gpderetta 6y ago
This feature will greatly simplify CRTP while also making it safer and more powerful.
It will also remove the need to of multiple pointless copy pasted overloads with different reference qualification on this.
On the balance I think the change will be an improvement.
Concepts could be used to make the error messages better, but TBH I don't have high expectations on concept error messages (they are still useful for other reasons though).
edit:
> Currently, there will be a short and helpful error message. With this proposal, this error message will be buried in the template instantiation details.
if there is a single overload, there is no point in using this feature. If there are multiple overloads, the error message is already not going to be very nice.
edit2:
In retrospect I think that the language should have had explicit 'this' from the beginning a-la python, with no difference between member functions and free functions (except for virtuals possibly) and '.' should have been just syntactic sugar. IIRC Bjarne thinks the same.
- choeger 6y agoYou are right in the observation that it will save some lines of code to be /written/. Whether or not that's an essential improvement for the writers of code, I don't know (one must weigh the cost of knowing the feature/pattern in the first place). But this perspective is essentially my grievance. C++ turns more and more into an exercise of programming the compiler. usability for people that want to use code is ever more deteriorating. There are more aspects like this in the language, for instance the fact that not even the std library can write out the return types or argument types of many functions. Or the hoops one has to jump through to deconstruct a std::variant (no one dared to add a proper sum type, but it is ok to implement one using the template interpreter).
- gpderetta 6y agoWell, I'm not completely disagreeing with you, but by experience, less line of code often translates in simpler to understand code in C++ if the removed code is just boilerplate (i.e. you are not just golfing). Concepts do help with the return type issue, at least now you can declare that your inferred return type conforms to some interface; for example: auto iterator take_n(auto range&& r, size_t n) {...} take_n is very generic and can return any type. But at least with concepts you can declare that it will look like an iterator. (in practice the result type depends on the range type and take_n declaration will show that). One problem with C++ is that the barrier for adding stuff to the standard library is much lower than adding it to the language. So for example we got std::bind well before we got lambdas; same thing will happen with variants (already in the library), proper union types and patter matching (there are proposals to add both the language).