3 ms·
I'd argue that the C preprocessor is the closest thing C++ has to Lisp macros. Templates are fundamentally based on static types, which are obviously something
by pcwalton 8y ago
I'd argue that the C preprocessor is the closest thing C++ has to Lisp macros. Templates are fundamentally based on static types, which are obviously something Lisp doesn't have.
- Yoric 8y agoWell, the C preprocessor is a pretty far cry from the kind of power of Lisp macros. If you want something as powerful as Lisp macros (ish), there isn't much else you can use in C++ land.
- pjmlp 8y agoYou can do quite a lot with if constepxr and TMO tricks, even stuff like generation of serialization code, even if isn't as clean as a Lisp implementation would be. And who knows, maybe by C++23 some form of reflection will be finally available.
- pjmlp 8y agoThat misses the point of duck typing in C++ templates, which is one of their great features, and also the cause of those wonderful instantiation error messages. In Lisp the same error would be a runtime one.