Scala's Macros and C++ templates both provide access to compile time meta-programming. Could you elaborate on similarities and differences? Are they equal in terms of expressiveness?
One important difference between them is that Scala macros are written in Scala, whereas C++ templates are their own programming language, which is completely unlike C++. C++ is an imperative object-oriented strict impure language, C++ templates are a declarative hybrid logic/functional non-strict pure language, which was never intended to be used as a full-fledged programming language, and thus lacks many of the features necessary for programming in the large.
They both provide compile time metaprogramming and both are turing complete, but that's about all they have in common. I am no expert on C++, but as far as I know, the fact that C++ templates are turing complete is rarely exploited and using them for actual programming is hard. Often, templates are just used to provide parametric polymorphism (aka generics), whereas Scala macros are written in Scala and can use the full power of the language at compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With