Think about how you might compile C++ templates without expanding them first. (You can’t)
-
-
Replying to @pcwalton
How is that a problem? And how does Rust do better?
1 reply 0 retweets 0 likes -
Replying to @basit_ayantunde
Compile times. And in Rust you can compile and typecheck templates without expanding them first.
1 reply 0 retweets 9 likes -
Replying to @pcwalton
Yeah, I suppose. I'm not certain as to whether that's possible with C++20 concepts yet. Also, that's an unfair comparison. The type systems are different, they perform different operations at compile time. I'm new to Rust though. Rust's generics seems to be type based.
1 reply 0 retweets 1 like -
Replying to @basit_ayantunde @pcwalton
A static assert for example in C++ can make a type invalid as a template parameter. Which you can't test until you perform a full expansion.
1 reply 0 retweets 0 likes -
Replying to @basit_ayantunde @pcwalton
C++ has true compile time polymorphism as each templated type can be totally different (methods, traits, content), which makes perfect sense. Cases like: Template Specialization (Class Members and Functions) Non-type Template parameters (evaluated and checked) Etc.
1 reply 0 retweets 0 likes -
-
Replying to @basit_ayantunde @pcwalton
A type has to be valid to be used as a template type param. Rust's generics only restricts types based on Traits, which is easy to check for and there's no need to expand.
1 reply 0 retweets 0 likes -
Replying to @basit_ayantunde @pcwalton
C++ has tonnes of ways of restricting types (including intrusively, unlike Rust) and a templated type can differ totally in member layout, members, methods etc. (also unlike Rust). Templated types are not necessarily correlated like in Rust.
1 reply 0 retweets 0 likes -
Replying to @basit_ayantunde @pcwalton
I'd say C++'s is more powerful. Though flawed but taking baby steps towards improvement, especially with the long-awaited Concepts, more like Rust Traits but far more expressive and powerful.
1 reply 0 retweets 0 likes
That expressive power also means that a C++ compiler has no choice other than to monomorphize everywhere.
-
-
Replying to @pcwalton
There are techniques to avoid that I suppose. E.g. Extern templates.
1 reply 0 retweets 0 likes -
Replying to @basit_ayantunde @pcwalton
C++ must always monomorphize because the language semantics require that you do overload resolution and selection of template specializations per instantiation. Concepts don’t fix that and don’t provide any feasible path toward fixing it. Rust did the right thing here.
2 replies 0 retweets 5 likes - 6 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.