Remix.run Logo
fooker 4 hours ago

C++ templates and metaprogramming is fundamentally incompatible with the idea of your code being treated in modules.

The current solution chosen by compilers is to basically have a copy of your code for every dependency that wants to specialize something.

For template heavy code, this is a combinatorial explosion.

WalterBright 4 hours ago | parent | next [-]

D has best-in-class templates and metaprogramming, and modules. It works fine.

direwolf20 37 minutes ago | parent | prev | next [-]

The compiler is supposed to put the template IR into the compiled module file, isn't it?

fooker 26 minutes ago | parent [-]

Exactly, that's no better than #including transitive dependencies to compile large translation units.

amluto 2 hours ago | parent | prev | next [-]

I think that SFINAE and, to a lesser extent, concepts is fundamentally a bit odd when multiple translation units are involved, but otherwise I don’t see the problem.

It’s regrettable that the question of whether a type meets the requirements to call some overload or to branch in a particular if constexpr expression, etc, can depend on what else is in scope.

direwolf20 33 minutes ago | parent [-]

This is one of those wicked language design problems that comes up again and again across languages, and they solve it in different ways.

In Haskell, you can't ever check that a type doesn't implement a type class.

In Golang, a type can only implement an interface if the implementation is defined in the same module as the type.

In C++, in typical C++ style, it's the wild west and the compiler doesn't put guard rails on, and does what you would expect it to do if you think about how the compiler works, which probably isn't what you want.

I don't know what Rust does.

pjmlp 4 hours ago | parent | prev [-]

It has worked perfectly fine while using VC++, minus the usual ICE that still come up.

fooker 4 hours ago | parent [-]

It works perfectly when it comes to `import std` and making things a bit easier.

It does not work very well at all if your goal is to port your current large codebase to incrementally use modules to save on compile time and intermediate code size.

pjmlp 2 hours ago | parent [-]

Office has made a couple of talks about their modules migration, which is exactly that use case.