It's worth nothing that a macro system plus basic reflection is where the real power of macros lies at.
It's worth nothing that a macro system plus basic reflection is where the real power of macros lies at.
In the cppawk project, which combines the preprocessor with Awk, I used the preprocessor to create an iteration syntax with a vocabulary of useful clauses that combine together for parallel or cross-product iteration.
Furthermore, the clauses are user-definable.
https://www.kylheku.com/cgit/cppawk/about/
What helps is that you don't have to deal with types and declaration syntax. So many of the ideas in cppawk will not translate back to C or C++, or not without wrecking the syntax with additional arguments and whatnot.
The man page for the <iter.h> header has a section on defining a clause; I provided an example of defining a clause that iterates on alpha-numeric string ranges like from "A00" to "Z99".
As an experienced Lisp programmer (and implementor), I had to rub my eyes several times to believe I had such a thing working, under such a universally maligned and reviled preprocessor.
The two for me fill different niches - for generic type-safe functions, parametrised types, etc. - templates. For text generation - macros. A hygenic macro system that lets you generate AST nodes and gives you access to type information would be absolutely divine, but it doesn't seem like we're getting it. Imagine if we had a script language that had full access to the compiler's internals.
That is what is missing piece of the puzzle.
Templates, man.
From the ref:
---
Conclusion
We attempted to represent ownership and borrowing through the C++ type system, however the language does not lend itself to this. Thus memory safety in C++ would need to be achieved through runtime checks.
Example code
#include <type_traits>
#include <utility>
#include <assert.h>
#include <stddef.h>
Templates it must be.
A good perspective.
That still doesn't help if you want the fields names.
But you are right that C++ templates are a bad functional programming language with duck typing.
The root cause is that template expansion is duck-typed. 'Concepts' are supposed to fix that, I heard.
#include <boost/spirit.hpp>
using namespace boost;
int main() {
spirit::rule<> group, fact, term, expr;
group = '(' >> expr >> ')';
fact = spirit::int_p | group;
term = fact >> *(('*' >> fact) | ('/' >> fact));
expr = term >> *(('+' >> term) | ('-' >> term));
assert( spirit::parse("2*(3+4)", expr).full );
assert( ! spirit::parse("2*(3+4", expr).full );
}
https://studylib.net/doc/10029968/text-processing-with-boost... slide 40What's C++ and what's regex?
(That's why it's great that Haskell and other languages in that family allow you to define your own operators, instead of eg re-using bit-shifting for IO.)
(Btw, parsing C++ is already Turing complete.)