5 ms·
C++ is Turing-complete, so you can do whatever you want. What Rust offers is an hierarchy free (i.e., no inheritance) polymorphism mechanism as a core part of
by humanrebar 12y ago
C++ is Turing-complete, so you can do whatever you want. What Rust offers is an hierarchy free (i.e., no inheritance) polymorphism mechanism as a core part of the language.
- detrino 12y agoThe turing-complete argument makes no sense here.
- humanrebar 12y agoSure it does. I can pass around a struct containing any bytes I want and do anything I want with it. If I want to define FatPointer that contains an opaque pointer (or some equivalent union) and a polymorphic Strategy object of some sort, I can. You can do the same in C, for that matter. Or in assembly. The reason we still come up with new languages is so that you can write code that conforms to certain patterns easily.
- jahewson 12y agoThat has nothing to do with Turing-completeness. There are Turing-complete languages which don't even have pointers.
- geofft 12y agoNo, Turing-completeness does not mean you can "do whatever you want". It means you can compute whatever you want that is computable. If the way you want to compute things is to embed a Rust compiler, yes you can do that, but there are many things that we'd colloquially refer to as "do whatever you want" that apply to the semantics of C++ itself. You cannot, for instance, create a new abstract base class and have a pre-existing class in someone else's header implement your abstract base class, such that a pointer to that pre-existing class can be dynamic_cast to your class. Because that statement refers to C++ semantics, not your ability to compute things, it's not affected by the claim of Turing-completeness.
- humanrebar 12y ago> You cannot, for instance, create a new abstract base class and have a pre-existing class in someone else's header implement your abstract base class, such that a pointer to that pre-existing class can be dynamic_cast to your class. Sure you can, for some value of base class and cast. You might not be able to use particular keywords, but data is data and math is math. You might not be able to use the built-in type system to do it. C and javascript programmers write their own inheritance-based type systems all the time. And anything you can do in C, you can do in C++ if you really want to.
- marrs 12y agoJS is a bad example because people who do that are preferring inheritance to composition, which is absurd. In the case of C, yes you can do that, and where performance is critical you might prefer to do it, but it's obviously not going to be your first choice if you have any sense.
- eli_gottlieb 12y agoI think he means that, through templates, the C++ type system is Turing-complete.
- steveklabnik 12y agoRust's is too.
- kibwen 12y agoThough the skimpy recursion limit makes it fairly impossible to do anything interesting with this property, much to the chagrin of some people. :P