3 ms·
I understood the first code listing, but then lost interest. In C++, classes can have member functions. Classes can also be derived from each other. A class D
by MathMonkeyMan 3y ago
I understood the first code listing, but then lost interest.
In C++, classes can have member functions. Classes can also be derived from each other. A class D derived from B inherits all of B's member functions.
So, when you have an instance of D calling one of its B-derived member functions, the B member function sees "this" as a pointer to a B, even though it is a pointer to a "D". That's fine because pointers to D are convertible to pointers to B.
What is proposed here is a way for one of B's member functions to say "this member function can be called only when the current object ('this') has a particular type." In the example, the particular type is "mut<B>", which is analogous to D.
My lizard brain doesn't see how this might be useful.
- paddim8 3y agoThe C++ designers are too obsessed with complexity. Complexity is not a good thing.
- riedel 3y agoThis article is not about C++ design as I read it, but rather about implementing a theoretical concept (qualifier subtyping) half-way using new features. I do not think that this is a real complex feature or something to do with complexity of language design in particular, it is rather like some weird tricks in python to implement obscure feature so they integrate well with general syntax. Or eg. like implementing something likes Duff's device in C to mock co-routines. (Having said that: to me the new C++ features are all too complicated. As someone coming from C C++ really now feels like its own language)
- jcelerier 3y ago> how this might be useful As always the goal in c++ is to put as much of the specification of your program in the type system and make sure that invalid state is unrepresentable (e.g. does not compile). This allows to very easily (compared to how'd you do it today) add custom compile-time checks to some variable.